# Using NPN transistors as on/off switches for a LED circuit

I have a very basic LED circuit: simulate this circuit – Schematic created using CircuitLab

All D# are 3Vx0.02A LED. In order for this circuit to work, we need a 25Ω resistor for each LED quartet:

Total LEDs current = 0.02A*4 = 0.08A
Voltage drop = 5V - 3V = 2V
Resistor value = 2V/0.08A = 25Ω


I didn't have a 25Ω resistor, so I put a 27Ω resistor instead.

Now, I want to add an Arduino in order be able to power on and off each LED quartet programmatically. I don't want to overload the Arduino, so I thought it would be ok to have an external power supply which will give the LEDs all the current they need to work, without worrying about burning the Arduino itself.

I thought I could either use transistors or MOSFETs as logical on/off switches, but I chose transistor because they are way less expensive than MOSFETs.

I thought about getting a 2N3904, because it supports up to 200mA and the circuit requires 0.08A per LED quartet.

So far I know the circuit should look something like this: simulate this circuit

I'm definitely not an electronic expert, I assumed it should be like that because I looked a site which talked about Arduino controlled LEDs via transistor used as on/off switches. It didn't explain a thing, it just had the circuit so what I want to ask is: why the 10kΩ resistor? Is the value right? Do I need a 1/4W 10kΩ resistor or a 1/2W one? The 27Ω resistor should remain 27Ω or should be changed when a transistor is introduced?

• It is usually a bad idea to groups LEDs together using only 1 current limiting resistor. This could lead to all kinds of problems such as unevenly lit LEDs. Dec 24 '16 at 19:30
• The above statement is pretty much FUD at this point. If you understand how leds work, paralleling them is fine. Look at any battery powered led string. All those leds are in parallel Dec 24 '16 at 20:03

Your basic concept is right, but there are some issues:

1. Paralleling 4 LEDs is not a great idea. It would be better to give each LED its own resistor. You say the LEDs drop 3 V. Figure about 200 mV for the saturated transistor, which leaves 1.8 V across the resistor. (1.8 V)/(20 mA) = 90 Ω. The common value of 100 Ω would work fine.

2. You have to consider the gain of the transistor in determining its base resistor. As you say, the transistor will pass 80 mA when on. Let's say we want to run the transistor at 20:1 collector/base current, since it can be counted on to have more gain than that. That means you want about 4 mA base current. If the digital output goes to 5 V when high, you have about 4.3 V across the resistor. That comes out to (4.3 V)/(4 mA) = 1.08 kΩ. We have some slop in the calculations so 1.1 kΩ should work fine.

In any case, 10 kΩ is likely too high. Working backwards, that provides 430 µA base current, which means you are relying on the transistor to have a gain of at least 186. That is well above the guaranteed minimum, so 10 kΩ is clearly too much resistance.

• which means you are relying on the transistor to have a gain of at least 186 - The datasheet says that the maximum HFE is 300. Is this information useful? Does it change something? What does it mean that HFE@100mA can be as low as 30 up to 300? Also, the datasheet says that the transistor collector/emitter voltage is 1V. Does this mean that the transistor will have a voltage drop of 1V, so I have to re-calculate the LED-resistor value for 0.8V drop instead of 1.8V? Dec 24 '16 at 19:42
• Typo, I think, in your last sentence. You mean 10 k and not 1 k.
– jonk
Dec 24 '16 at 19:43
• @Back: Maximum Hfe is irrelevant here. We have to design the circuit to work with the smallest gain the transistor might have. In this circuit, higher gain causes no problem, and it would work with infinite gain just fine. Dec 24 '16 at 20:03
• @OlinLathrop What about the question on the voltage drop? Dec 24 '16 at 20:08
• Whoever downvoted this, what exactly do you think is wrong, misleading, or badly written? I'm not seeing it. Dec 24 '16 at 20:09

The 10K ohm resistor is there to reduce the current the Arduino's output will need to provide. Otherwise the Arduino will be "looking at" about 0.6 volts which it will try to pull up to about 5 volts. Something will have to give and it will probably be the Atmel processor's output.

So, that is why you need to go through a resistor. But why 10K ohms? Most common transistors will have a beta of about 100. That is, the base to emitter current x 100 is about equal the collector to emitter current.

So, the current in the base to emitter path is ((5V - 0.6V) / 10,000) or about 0.44mA. Multiply that by 100 gets you 44mA for the collector to emitter current. Which is less than the 80mA you had calculated was necessary. So your circuit may not work. To make a circuit that will work consider changing this resistor from 10K ohms to 5K ohms or even 1K ohms.

Also, you should avoid grouping LEDs using a common current limiting resistor. This could lead to several problems. One of which could be unevenly lit LEDs. Instead consider the following example from http://playground.arduino.cc: 