Pages: [1]   Go Down
Author Topic: Powering LEDs using transistors controlled by arduino mega  (Read 1332 times)
0 Members and 1 Guest are viewing this topic.
Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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 smiley

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 Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Faraday Member
**
Karma: 98
Posts: 3598
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Faraday Member
**
Karma: 67
Posts: 2674
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

The way you have it in your schematic isn't the same as how you have it wired up!

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3598
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Made an Edit, added missing resistor to collector
« Last Edit: January 14, 2013, 03:09:11 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 95
Posts: 4315
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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
Offline Offline
Brattain Member
*****
Karma: 536
Posts: 27061
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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.

http://www.onsemi.com/pub_link/Collateral/P2N2222A-D.PDF
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 Offline
Edison Member
*
Karma: 34
Posts: 1319
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 smiley-razz

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
Offline Offline
Brattain Member
*****
Karma: 536
Posts: 27061
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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
Offline Offline
Brattain Member
*****
Karma: 536
Posts: 27061
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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
Jump to: