Go Down

### Topic: Powering LEDs using transistors controlled by arduino mega (Read 5095 times)previous topic - next topic

#### Getronicle

##### Jan 14, 2013, 08:21 pmLast Edit: Jan 14, 2013, 08:53 pm by Getronicle Reason: 1
Hi, hope this is the correct place to put this, this is my first post

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

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

#### jerseyguy1996

#1
##### Jan 14, 2013, 08:44 pm
The way you have drawn that, the Cathode and Anode are at the same potential so no current will flow through the LED's.
Arduino Uno;
Mega328

#### HazardsMind

#2
##### Jan 14, 2013, 08:45 pm
Whos schematic is that? The LEDs are wired wrong, they are shorting themselves out. Fix their wiring, it should be:

from transitor
|
| -|<| --|
| -|<| --|
| -|<| --|
| -|<| --|
|
gnd
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

#### Getronicle

#3
##### Jan 14, 2013, 08:47 pmLast Edit: Jan 14, 2013, 08:54 pm by Getronicle Reason: 1
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.

#### larryd

#4
##### Jan 14, 2013, 08:58 pm
Put the LEDS and R1-3 before the collectors.
Emiters go to ground.
No technical PMs.
The last thing you did is where you should start looking.

#### HazardsMind

#5
##### Jan 14, 2013, 09:04 pmLast Edit: Jan 14, 2013, 09:09 pm by HazardsMind Reason: 1
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
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

#### JimboZA

#6
##### Jan 14, 2013, 09:07 pm
And presumably the Arduino ground is common with the LEDs' power supply ground.....
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

#### Getronicle

#7
##### Jan 14, 2013, 09:09 pm
Haven't had much experience using transistors in practice, that's why. Thanks for advising.

Does anyone have any knowledge regarding values?

#### CrossRoads

#8
##### Jan 14, 2013, 09:33 pm
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.

http://www.onsemi.com/pub_link/Collateral/P2N2222A-D.PDF
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### DVDdoug

#9
##### Jan 14, 2013, 09:49 pm
Quote
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 Ohm's Law 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.

Quote
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.

#### Getronicle

#10
##### Jan 14, 2013, 10:23 pm
Quote
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?

Quote
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

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.

#### CrossRoads

#11
##### Jan 14, 2013, 10:30 pm
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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Getronicle

#12
##### Jan 14, 2013, 10:41 pm

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.

#### CrossRoads

#13
##### Jan 15, 2013, 01:58 am
Makes sense if you have something existing already.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up