Powering LEDs using transistors controlled by arduino mega

Hi, hope this is the correct place to put this, this is my first post :slight_smile:

I'm not new to electronics but I'm new to arduino and what it likes/doesn't like. I'm looking for some advice regarding using transistors to switch current from a 9V battery to groups of 4 parallel LEDs. There are 25 groups, so 100 LEDs in total (think of it as a 5x5 matrix, where there are 4 LEDs for every 1). Each group will be switched by its own transistor using an arduino mega.

This schematic shows 3 of these groups to give you an idea:

I know it's not good practice to use only one resistor to limit the current going to parallel LEDs, but it works and the resistance is enough to prevent a single LED blowing.
Using a 9V source and a 360 ohm resistor each LED receives 6.25 mA of current. If all LEDs are on at once, a current draw of 625 mA from the battery will be required. I am willing to add another 360 ohm resistor to each group to lower the current as the brightness of the LEDs does not suffer too much when I do this.

I plan on using 2N2222 NPN transistors which have a beta value of ~100, so what I want to know is:

  • What base current would be required from the arduino to provide an emitter current of 25 mA (from the battery)?
  • Will the arduino be able to provide enough current to all pins so that 625 mA will be drawn at once? (I will be using a pin for each transistor as I will not be multiplexing). In the case that I double the resistance of each group from 360 to 720 ohms, the max current will be 312.5 mA.

Am I going in the wrong direction completely?
I would really appreciate any help any of you could give me, thanks :slight_smile:

Edit: I have just realised my schematic is slightly off - the LEDs are connected correctly in reality.

The way you have drawn that, the Cathode and Anode are at the same potential so no current will flow through the LED's.

Whos schematic is that? The LEDs are wired wrong, they are shorting themselves out. Fix their wiring, it should be:

from transitor
|
| -|<| --|
| -|<| --|
| -|<| --|
| -|<| --|
|
gnd

Yeah I just edited my post, I drew the schematic quickly and made the mistake. Apologies.

Edit: I've modified the schematic to match the correct configuration.

Put the LEDS and R1-3 before the collectors.
Emiters go to ground.

Why are you powering the LEDs from the emitter, that is a bad way to do it. Usually it is like this:
Vcc
Z
Z
|
x------------(Out to LEDs)
|
| /
o---VVV------| (NPN)
|
v
|
Z (only needed to limit current, otherwise emitter to GND)
Z
|
GND

Made an Edit, added missing resistor to collector

And presumably the Arduino ground is common with the LEDs' power supply ground.....

Haven't had much experience using transistors in practice, that's why. Thanks for advising.

Does anyone have any knowledge regarding values?

If that is a small squarish 9V battery, you will find they don't have much longevity, with just a few hundred mAH of capacity.

You could organize the LEDs to better use the available voltage and current.
Instead of having all 5 LEDs in parallel, you could have at least 2 in series sharing the same 6.2mA of current, and maybe even 3 depending on the Vf of the LEDs, each transistor then driving 2 or 3 strings of LEDs (vs 5 strings of 1 LED). You will need another resistor or two per LED, but your current draw will be greatly reduced without reducing brightness.

9V - resistor - LED anode, cathode to next LED anode, cathode to NPN collector, emitter to Gnd.

Then each transistor will only switch 18-19 mA, and not 31-32mA.
To turn on the 2n2222a, a base resistor of ~390 ohm will let ~11mA into the base which, should be enough for full turn on at the low current levels you have.

Does anyone have any knowledge regarding values?

Assuming an hfe of 100, you need at least 1/100th of the LED current into the transistor base. A reasonable rule-of-thumb is 1/50th to 1/20th (2%-5%) to make sure the transistor turns all the way on ;(saturates). You can use [u]Ohm's Law[/u] to make some calculations. But just as a rough guess, The Arduino is supplying slightly voltage than is "seen" by the LED current-limiting resistor. So, let's say 20 times the LED resistor, or somewhere around 7-8k Ohms. If the LEDs are well-matched, and if you never have to replace on with one from a different batch, you may be able to get away with it.

know it's not good practice to use only one resistor to limit the current going to parallel LEDs, but it works and the resistance is enough to prevent a single LED blowing.

Do you know why it's bad practice? ...The current (around 25mA in your case) gets divided among the parallel LEDs, but it does not necessarily get divided evenly, depending on variations in LED characteristics. That means some LEDs may be brighter than others.

It would be better to put the LEDs in series (or maybe pair them in series). There is a trade-off here, because wiring LEDs in series increases the voltage across the LEDs and reduces the voltage across the resistor. The lower the voltage across the current limiting resistor, the more sensitive it is to supply variations, and the brightness variation with power supply variations (such as an aging battery) will be worse.

Assuming an hfe of 100, you need at least 1/100th of the LED current into the transistor base. A reasonable rule-of-thumb is 1/50th to 1/20th (2%-5%) to make sure the transistor turns all the way on ;(saturates)

This is mainly what I was getting at. If I wanted a 625 mA current, then providing 1/20th of that value to the base I would need a total arduino output of 31.25 mA. I would guess that this is well within the limits of the arduino?

Do you know why it's bad practice? ...The current (around 25mA in your case) gets divided among the parallel LEDs, but it does not necessarily get divided evenly, depending on variations in LED characteristics. That means some LEDs may be brighter than others.

I understand this principle, however I'm not too worried because even if one LED pulls a lot of the current it needs to be at least 20 mA to fail. Seeing as the LEDs have the same specifications I don't imagine a single LED pulling more >20 mA, leaving <5 mA for the other 3. Maybe I'm wrong on this though :stuck_out_tongue:

CrossRoads - Thanks for that information. However I think I would prefer to stick with the original parallel configuration because, for me, preserving as much brightness as possible is more important than total power consumption for the moment - based on the issues mentioned by DVDdoug. I'll probably apply your advice to another project I'd like to do.

Thanks for the help.

Two LEDs in parallel each drawing 6.25mA will be the same brightness as 2 LEDs in series each sharing the same 6.25mA.
Drawing twice the current will certainly age the battery faster.

CrossRoads:
Two LEDs in parallel each drawing 6.25mA will be the same brightness as 2 LEDs in series each sharing the same 6.25mA.
Drawing twice the current will certainly age the battery faster.

I understand this and would implement it but I'm actually using something I built before which was powered directly by a battery and I'd rather not build something completely from scratch. I'm pretty much intervening where I can in the circuit. When I want to build another I'll probably do as you advised.

Makes sense if you have something existing already.