# Turning on multiple leds with arduino using transistor

I want to be able to turn on 50 red LEDs with one pin of an Arduino. I don't want individual control, I just want to be able to turn them all on or all off.

I found this example. It uses a 2N3904 transistor. Is this the approach I want to take? I presume I would need a higher power transistor?

I am using an external power supply that is wired into a custom board with a 5v voltage regulator so I am powering the LEDs directly from this regulator.

The LEDs come in the form of this LED light bar array (or at least very similar)...

I had mentioned in a comment in an answer below that I was using a 330 ohm resistor with each LED. On another part of this project, I use the light bars as level meters, and each separate LED is controlled via a shift register, thus the separate resistor. I realise after thinking about it that I don't need to have a resistor in series with each LED for this now as they are either all on or all off (hmmm.... sorry for my rather haphazard comments!).

I did have a thought that I could have some sort of electronic switch that can disconnect ground or 5V. Is this viable?

• This is for a software controller I am making. The lights need to be able to respond relatively quickly (ie every 200 milliseconds) – Adam Apr 17 '13 at 19:32
• The software is easy to figure out. I think a bit more explanation of the hardware would help. What sort of LED bar are you using? Are the LEDs in series, parallel, common cathode, common anode or all independent? Does "powering the LEDs directly from the mains" mean from the 5V regulator? Because that could be taken to mean many other things. You mentioned a 330 ohm resistor per LED... so each LED (all 50 of them) has a series resistor? Just trying to clarify so we can give you the best possible answer. – Kurt E. Clothier Apr 17 '13 at 19:43
• Hi Kurt, I've edited my original post with the info. Cheers – Adam Apr 17 '13 at 19:57

A transistor is basically a switch that can disconnect ground or 5V. There are transistors of all sorts, and some can switch truly huge loads. 50 LEDs is no big deal.

So, the question then is this: Can a single 2N3904 switch 50 LEDs?

To answer that, we'd need to know first what kind of LEDs. But let's assume you are using the usual nothing-special variety. A reasonable estimate of the maximum current of these is $20mA$. If you have 50, then the maximum current is $20mA \cdot 50 = 1000mA$. Looking at the datasheet I see the maximum collector current for 2N3904 is $200 mA$. So the answer is no: you can not switch 50 LEDs with one 2N3904.

I suppose you have several options:

• use multiple 2N3904
• use fewer LEDs
• use the same LEDs, but drive them with less current
• use a bigger transistor (TIP121 is very easy to find)
• use some other switching device

Of these, I think reducing the LED current or using a larger transistor is probably the most likely solution. Other switching devices (like a relay) are probably more expensive and slower.

• * Use a IRLML2502 MOSFET, my favorite component of the day. :-) – Anindo Ghosh Apr 17 '13 at 19:20
• I'm using a 5 red LED lightbars (10 LEDs in each). I am using a 330 ohm resistor in series with each LED, so I'm looking about 2 mA per LED. This totals less than the specs of the transistor (I think - I always get a bit confused at calculating total current usage!) – Adam Apr 17 '13 at 19:31
• That seems unlikely. Your resistor would account for a voltage drop of 330Ω x 0.002A = 0.66V, so unless your LEDs have a Vf of 4.34V (which would be uncharacteristically high for red LEDs), your current is likely to be considerably higher. – microtherion Apr 17 '13 at 20:01
• This answer only considers the leds wired in parallel. The leds could be two in series. So the current would be 20mA * 25 chains. But @Adam 2mA is low for a led, do they even light up at that current draw? – Passerby Apr 17 '13 at 20:36
• @Passerby, understandable. I'm sure some of the high power ones do require a bit more to turn on. But the common LEDs I have worked with are plenty happy with small (even much less than 1mA) currents, although they do not shine very bright. In fact, the LEDs in this project of mine only use 1.8mA each. And since they are multiplexed and only on 1/3 of the time, the effective current is more like 0.6mA. Even still, the display is easily visible in bright light from a decent distance. projectsbykec.com/projects/miscellaneous/… – Kurt E. Clothier Apr 18 '13 at 11:17

Considering the information given (50 Red Leds Noted at 1.95V, 5v Source, 2mA current, 330Ω resistors), the following would work.

Taking into account the common Led resistor calculation:
(Vcc - Forward Voltage) / Current
Where Vcc is 5v, Forward Voltage is 1.95v per led, since we have two in series, 1.95v * 2, and Desired Current is 2mA.
(5 - (1.95 * 2)) / 0.002 or (5 - 3.9) / 0.002 or 1.1 / 0.002 = 550.
Since you have 330Ω resistors, adjusting for that would give 3mA per Series. Not per led, but per series, as current is equal in a series path. Each series of resistors, in this case two, would use the same 3mA of current. So this simplifies the equation to 3mA * 25 series chains, only 75mA that needs to be switched.

Any common small signal transistor like the 2n3904 can handle 75mA without issue. A 1kΩ base resistor is used between the transistor base and the MCU pin.

Note, the schematic below only shows one led bar, you would just add the rest in the same fashion. Wire the first led's cathode to the next led's anode, and one resistor per pair.

simulate this circuit – Schematic created using CircuitLab

You should use the pin on the Arduino to control a transistor that turn on a relay and the relay contacts turn on the all the LEDs by apply ground. If you must use a transistor, then yes you need to find one that can handle all the current. Even with a relay, be sure to check the contact current ratings. See sample circuit below. Depending on the current rating and coil resistance of the relay you select, you may or may not need R2.

• A relay has a relatively high switching time, and limited mechanical life. It might be worth asking OP to confirm that they do not want to switch the LEDs very rapidly or too often. – Anindo Ghosh Apr 17 '13 at 19:30
• Thanks. I think a relay would be too slow for my application. I have added a comment to my original post. – Adam Apr 17 '13 at 19:33
• There is absolutely no point in using a relay when so many transistors are available which can switch very large currents! Aside from the slow speed and huge size of relays, electrical solutions almost always outlive and out-perform mechanical ones. – Kurt E. Clothier Apr 17 '13 at 19:35
• While Relays might not be the best option, they are a viable option (speed not withstanding). +1 to make up for whomever downvoted. – Passerby Apr 17 '13 at 20:38
• That's what I meant: it's not the best option, but I wouldn't down vote it... If any sort of pulsed control is used, a relay will have a very short life span if can handle the pulse speed at all. – Kurt E. Clothier Apr 18 '13 at 0:32