Pages: [1]   Go Down
 Author Topic: Powering LEDs using transistors controlled by arduino mega  (Read 769 times) 0 Members and 1 Guest are viewing this topic.
Ireland
Offline
Newbie
Karma: 0
Posts: 5
 « on: January 14, 2013, 02:21:44 pm » Bigger Smaller Reset

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.
 « Last Edit: January 14, 2013, 02:53:55 pm by Getronicle » Logged

0
Offline
Sr. Member
Karma: 3
Posts: 268
Arduino rocks
 « Reply #1 on: January 14, 2013, 02:44:21 pm » Bigger Smaller Reset

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

Arduino Uno;
Mega328

Queens, New York
Offline
Karma: 59
Posts: 2732
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
 « Reply #2 on: January 14, 2013, 02:45:49 pm » Bigger Smaller Reset

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

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

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Ireland
Offline
Newbie
Karma: 0
Posts: 5
 « Reply #3 on: January 14, 2013, 02:47:41 pm » Bigger Smaller Reset

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.
 « Last Edit: January 14, 2013, 02:54:34 pm by Getronicle » Logged

Offline
Edison Member
Karma: 45
Posts: 1821
The last thing you did is where you should start looking.
 « Reply #4 on: January 14, 2013, 02:58:24 pm » Bigger Smaller Reset

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

Queens, New York
Offline
Karma: 59
Posts: 2732
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
 « Reply #5 on: January 14, 2013, 03:04:05 pm » Bigger Smaller Reset

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

 « Last Edit: January 14, 2013, 03:09:11 pm by HazardsMind » Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Johannesburg UTC+2
Offline
Karma: 60
Posts: 3241
 « Reply #6 on: January 14, 2013, 03:07:53 pm » Bigger Smaller Reset

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

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

Ireland
Offline
Newbie
Karma: 0
Posts: 5
 « Reply #7 on: January 14, 2013, 03:09:55 pm » Bigger Smaller Reset

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

Does anyone have any knowledge regarding values?
 Logged

Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 413
Posts: 22679
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
 « Reply #8 on: January 14, 2013, 03:33:50 pm » Bigger Smaller Reset

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.

 Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline
Edison Member
Karma: 19
Posts: 1122
 « Reply #9 on: January 14, 2013, 03:49:34 pm » Bigger Smaller Reset

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

Ireland
Offline
Newbie
Karma: 0
Posts: 5
 « Reply #10 on: January 14, 2013, 04:23:52 pm » Bigger Smaller Reset

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

Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 413
Posts: 22679
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
 « Reply #11 on: January 14, 2013, 04:30:57 pm » Bigger Smaller Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Ireland
Offline
Newbie
Karma: 0
Posts: 5
 « Reply #12 on: January 14, 2013, 04:41:09 pm » Bigger Smaller Reset

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

Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 413
Posts: 22679
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
 « Reply #13 on: January 14, 2013, 07:58:35 pm » Bigger Smaller Reset

Makes sense if you have something existing already.
 Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

 Pages: [1]   Go Up