Calculate transistor collector and base resistors values for driving LED with GPIO

I try to learn how to use a transistor and how to calculate the necessary resistances. Here's what I calculate for the moment. I do not know at all if I left properly and if my equations are good. I think the equation for R2 is not good. How should I go about it? I also learn to read the data sheet of a transistor. Any help is welcome. Thank you

EDIT: it's WORKING

using factor of 10, using β = 100, R1 = 55Ω and R2 = 1325Ω precisely using potentiometers ... The LED does light when I connect a voltage 3.3 V on the base of the transistor, success.

• For a start: $\frac{5-3.9}{0.02} \neq 250$ – Huisman May 7 '19 at 13:42
• Thank's for that, I'm confuse – Ephemeral May 7 '19 at 13:44
• I think the equation for R2 looks OK. I would do: $V(R_2)$ = 3.3 - 0.65 = 2.65V. I choose a base current that is 10x smaller than the collector current of 20 mA (to make the transistor operate well into saturation mode) so $I_B$ = 20 mA / 10 = 2 mA. Then R2 = 2.65 V / 2 mA = 1325 ohm, same as you get. – Bimpelrekkie May 7 '19 at 13:51
• But I still do not understand why we chose a value 10 times lower As explained: I choose the factor to be 10. The NPN has a $\beta$ = 100, so if I would use that and make $I_B$ smaller (0.2 mA) then the NPN sets the current as it will be close to active mode operation. I don't want that! I want saturation. So I apply 10x more $I_B$ to make sure. – Bimpelrekkie May 7 '19 at 14:01
• You can forget about $\alpha$, you don't need it. Also note that although the datasheet says $\beta$=100, the actual value can change a lot. Like between 50 and 200. It depends on the actual transistor you're using. For properly designed circuits this does not matter, that's why I use a 10x larger $I_B$ so that even if $\beta$=50, I'm still OK and well in saturation. – Bimpelrekkie May 7 '19 at 14:25

I drive from Atmega328P and similar a lot. Need to limit the current from the uC. These methods work pretty well, and the transistor characteristics do not matter so much. If you have known values (Vbe, Vce, Vf, Rds), plug those in.

For R1, base resistor, assuming Vbe of 0.7V for R1, and current flow of 20mA to push transistor into saturation, then (5V - Vbe)/.02A = resistor.

If a MOSFET, have to deal with gate input capacitance, then its just 5V/.02A for the resistor. That capacitance looks like a short (to Gnd when driving high, and to Vcc if driving it low), so the resistor just limits the initial current rush as the cap charges or discharges.

Select R2 to limit the LED current. Assuming Vce of 0.7V, Vf of LED (you can use a 5V source and 1K resistor and measure it), then R2 = (Vsource - Vf - Vce)/0.02A (20mA) = resistor value. Maybe even solve for 10mA, or 5mA, modern day LEDs can be really bright at 20mA, and it also depends on the lens type, and the color. Old LEDs had poor brightness, new ones are much brighter.

• Thank you, If I understand correctly: $Vs = 5.;$If = 0.02; $Vbe(sat) = 0.65;$R1 = (($Vs -$Vbe(sat))/$If) = 217.5 Ohms;$Vf = 3.9; $Vce(sat) = 0.2 ;$R2 = (($Vs -$Vf - $Vce(sat))/$If)= 45 Ohms; – Ephemeral May 7 '19 at 15:22
• For me R2 = RB ... I'm confuse again – Ephemeral May 7 '19 at 15:27
• Looks correct. Vf of 3.9V is high, is that a white, or blue, or IR LED? Those typically have high Vf like that. (5V - 3.9V - 0.2V)/45 ohm = 20mA. Standard values of 50 ohm would do fine for R1, and 220 for R1. – CrossRoads May 7 '19 at 15:30
• Just reverse them then. R2 = (5V - Vbe)/.02A. R1 = (5V - Vf - Vce)/.02A. Just a name at this point. Base resistor of 220 ohm, LED current limit resistor of 50 ohm. – CrossRoads May 7 '19 at 15:34
• Thank you again, It's a blue led 3.9@20mA. "50 ohm would do fine for R1, and 220 for R1" ? Sorry , Did you mean 220 Ohms for R2 ? knowing that for my case R2 = RB ? (I am not English and I find it difficult to find myself :) – Ephemeral May 7 '19 at 15:34