# 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, 2016 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, 2016 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, 2016 at 19:42
• Typo, I think, in your last sentence. You mean 10 k and not 1 k.
– jonk
Dec 24, 2016 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, 2016 at 20:03
• @OlinLathrop What about the question on the voltage drop? Dec 24, 2016 at 20:08
• Whoever downvoted this, what exactly do you think is wrong, misleading, or badly written? I'm not seeing it. Dec 24, 2016 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: If you want to read more about using transistors as switching read this web page.

• Thank you! What about the resistor? Should it be a 1/4W one or a 1/2W one? Also, the datasheet says that VCE is 1V: does it mean that I should change the 27Ω resistor to a 15Ω resistor (voltage drop of 1V instead of 2V)? Dec 24, 2016 at 19:26
• I did not build the circuit yet, I'm trying to understand if it is right before doing anything, also because I still need to buy some parts so I want to be sure everything is correct before buying. You talk about beta: I can't find it in the datasheet, is it the HFE? If yes, the datasheet says that with 100mA of collector current, the HFE goes from a minimum of 30 to a maximum of 300. Which value should I consider and why? Dec 24, 2016 at 19:34
• Well, I think your circuit will not work because the beta (Hfe) is only 100 and the current going into the base is too low to support passing 80mA from the collector to the emitter. So, if it works, great, if it doesn't, consider reducing the 10K ohm resistor to 5K ohms or even 1K ohms. At 1K ohms the current would be increased from 0.44mA to 4.4mA. This is still very low and you can get by with a very low wattage resistor. Dec 24, 2016 at 19:38
• Those Hfe values are the range you might find in a batch of transistors. Again, you are mostly interested in cut-off and saturation. (We're not building a high end amplifier here using transistors with matching Hfe's.) All you need to do is make sure the circuit will work. Using 10K ohm may or may not work, using 5K ohms might work and using a 1K ohm will probably work. Dec 24, 2016 at 19:42
• Ok that's clear. Last question (in the first comment): Right now the LED resistor has a voltage drop of 1.8V; the datasheet says that the collector/emitter voltage for the transistor is 1V. Does this mean that the transistor has a voltage drop of 1V and I should re-calculate the LED resistor value for a voltage drop of 0.8V instead of 1.8V? Dec 24, 2016 at 19:47