0
\$\begingroup\$

I want to use a 12F675 to turn on two LEDs. After a little research, I decided to use a 2N2222A NPN transistor and 2 LEDs in series (2V-drop 20mA consumption.)

As I read in datasheet, microcontroller provides 20mA on the output pins. Can you please explain me how to saturate the transistor? How do I calculate Rb (base resistor) to fully turn on a transistor?

This "project" is used to learn how to work with electronic components and get familiar with microcontrollers and programming languages.

\$\endgroup\$
3
  • \$\begingroup\$ With Vdd=+5V, your 2-series LEDs (2V+2V) requires a 50 ohm series resistor to get 20mA flowing. 12F675 GPIO should be able to drive this series-string (LED+LED+50ohm) directly. I would use active-low drive: LED anodes point toward Vdd, and you turn them ON by commanding GPIO to go LOW (zero volts). This drive method suggestion pushes 12F675 close to its current limits, but should be OK. Seems like your LEDs are red. I doubt this would work with blue or white LEDs. \$\endgroup\$
    – glen_geek
    Commented Jan 26, 2023 at 14:49
  • 3
    \$\begingroup\$ "to get full open transistor" -- here's one thing to learn. In English technical usage, a switch is off when it is open (contacts not touching) and on when it it closed. Also in English technical usage, a transistor is a switch -- it is "open" when it is not conducting. Given the number of people in the last decade or so who seem to be adopting the exact opposite usage, I suggest you get into the habit of saying "on" and "off" -- that will be clear to all. \$\endgroup\$
    – TimWescott
    Commented Jan 26, 2023 at 16:31
  • \$\begingroup\$ @Skepsis - I'm a moderator on this site. || I have edited your question to follow the suggestion made by Tim Wescott. This is extremely important and his advice is very good. || The term "open" is used in electronics to mean "off" / no on / no circuit and similar. An "open circuit" means one with infinite resistance where no current can flow. So saying "fully open" means "completely turned off". This is completely standard usage and using the term "open" to mean "on" will cause massive confusion and wrong results. \$\endgroup\$
    – Russell McMahon
    Commented Jan 31, 2023 at 9:16

2 Answers 2

1
\$\begingroup\$

The saturation occurs when the beta (collector current to base current ratio) comes out of play.

One practical way I've been using for years is to select the collector-current-to-base-current ratio as "one tenth of the minimum datasheet-specified beta". From transistor to transistor this can vary a lot but for small signal transistors and low currents (e.g. less than 500 mA) something between 10 to 20 should be alright.

transistor characteristics from datasheet

(Image source: OnSemi P2N2222A datasheet)

For your case (20 mA), the beta seems to be somewhere between 75 and 100. To saturate, I'll select a ratio of 7.5:

schematic

simulate this circuit – Schematic created using CircuitLab

$$ \mathrm{I_B = I_C / 7.5 = 2.7 mA \\ R_B = (V_G - 0.7)/I_B} $$

VG here is the output voltage of GPIO when it's outputting logic-1. So, for 4.5V, the base resistor can be 1k5. For 3.3V, it'll be 1k.


If turning on and off is the main purpose then you can use an NMOS such as 2N7000 (or 7002). Even without a resistor (normally you'll require one but let's ignore) you can use it as a switch.

\$\endgroup\$
6
  • \$\begingroup\$ Thank you! I think I get the point! Now I have to search about output voltage of I/O pins of 12f675. For the moment the purpose is just to ON/OFF LED, but later I want to use PWM, so I think 2n2222 is OK. What do you think? \$\endgroup\$
    – SkePsis
    Commented Jan 26, 2023 at 13:57
  • \$\begingroup\$ @SkePsis 2N2222 is OK but, as I stated in my answer, consider an NMOS as well. \$\endgroup\$ Commented Jan 26, 2023 at 14:13
  • \$\begingroup\$ You may want to ask a separate question about PWM. The short answer is that a simple transistor circuit will switch PWM adequately at low audio frequencies (certainly 100Hz for a tossed-together circuit, maybe 1kHz, but the circuit shown almost certainly would not be able to keep up with 10kHz). \$\endgroup\$
    – TimWescott
    Commented Jan 26, 2023 at 16:34
  • \$\begingroup\$ Thank you, I will replace my 2n2222 with your NMOS. Did you have some materials from study frequency? I did no have any idea how to select frequency for PWM. \$\endgroup\$
    – SkePsis
    Commented Jan 30, 2023 at 6:55
  • 1
    \$\begingroup\$ @SkePsis Here's a basic info: Check the maximum current for GPIO first and place a series resistor from GPIO to gate (a.k.a. gate stopper, Rb shown in the circuit in my answer) accordingly. For example, if the max current is 20 mA per GPIO and if the output voltage is 3.3V then the gate stopper should be at least Rb = 3.3V / 20mA = 165 Ohms. Also, Rb and the input capacitance of the MOSFET (Ciss as in the datasheets) form a low-pass filter. Make sure the cut-off frequency of this filter, \$f_c=1/(2\pi R_b C_{iss})\$, is 5 to 10 times the PWM frequency. \$\endgroup\$ Commented Jan 30, 2023 at 8:30
0
\$\begingroup\$

If your LED load (20 mA) is in the collector up to the positive supply then, to get reasonably good transistor saturation (low \$V_{CE(ON)}\$) you should typically assume the base current needs to be about one-tenth of the load current.

So, you need to choose a base resistor that gives about 2 mA into the base. This of course assumes you are using the BJT in a common emitter configuration and that you have a collector resistor in series with the LEDs to limit the current to 20 mA.

If your MCU can output 4.5 volt at 2 mA, then the resistor will need to be about 3.8 volts ÷ 2 mA = 1900 Ω.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for clarification. Could you please show me where I can get information about output voltage of 12f675? I searched in datasheet, and get "D080 - I/O ports 0.6V IOL=8.5mA , Vdd=4.5V) \$\endgroup\$
    – SkePsis
    Commented Jan 26, 2023 at 13:56
  • \$\begingroup\$ It will be in the data sheet @SkePsis \$\endgroup\$
    – Andy aka
    Commented Jan 26, 2023 at 14:03
  • \$\begingroup\$ Could you, please, tell me the name of parameter? Or where should I research (a chapter)? I take a look but anything about voltage... \$\endgroup\$
    – SkePsis
    Commented Jan 26, 2023 at 14:04
  • \$\begingroup\$ I haven't got the data sheet. \$\endgroup\$
    – Andy aka
    Commented Jan 26, 2023 at 14:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.