A whole lot of LEDs

I'm going to be ordering my Arduino soon from Sparkfun - I can't wait - but I need to see if I need to order/buy anything else. What I want to do is have the Arduino power a bunch of LEDs. I have four groups with 5 pairs of LEDs in them (total 40). Eventually I may add more pairs to each group. Each group will have a corresponding pair lit at the same time. I'm pretty new to this stuff so how would I go about doing this? Sorry if this has been asked before, I searched but did not find much. Thank you!

Just go to your local electronics store and ask for

  • a 330 ohm, 1/4 watt resistor for each LED (assuming you'll use red, green or yellow LEDS, this is a safe value)
  • a 2n2222 or 2N3904 transistor for each "bunch" of leds that will be controlled by one pin (2N3904 is good for switching up to about eight LEDS, and 2N2222 can switch up to 30 LEDS, or even a few more)
  • a 1K or 2.2K, 1/4 watt resistor for each transistor.

For what you describe, it should cost you about $2 for all of the above, without the leds. In the central part of North America at stores called "Radio Shack", multiply the cost by seven. Try to find a real electronics store/supplier in your town.

The circuit is Here.

The transistors above are generally emitter-base-collector if you look at them from the front, reading left to right.

hope this helps

D

Daniel thanks! That's good I can get that stuff at Radio Shack (used to go in there all the time when I was young[er]). Would it be ok to use these prewired LEDs (in red)? Lastly, is the code any different or is it just like the blinking LED example? Thank you so much!

BTW That's cool you have the one free minute thing on your site. I've seen that around.

In circuits like this, where you are driving a bunch of LEDs as a unit, I have found that you don't need a dedicated resistor for each LED. For example, in the schematic given, you can calculate the equivalent resistance of all four 330-ohm resistors in parallel, which is 330/4 = 82.5 ohms. So find a single resistor in the 80 to 90 ohm range, wire one side to the Arduino +5V, the other side to all the positive LED terminals connected together, and the rest of the circuit remains the same.

This works because the four resistors in the given schematic have, in theory, identical current flowing through them, and therefore identical voltage drop across them, so it is as if the bottom of all the resistors are connected, due to the voltage at the bottom of each being identical. If they were connected, you would have four resistors in parallel, hence the 330/4 formula above.

Note that this does NOT work if you are trying to turn on/off LEDs independently of each other; in that case, each LED must have an independent resistor in order to safely limit the current flowing through the LED. This trick also assumes that all the LEDs are the same kind, and all are connected to the same transistor driver, so that the assumption of identical current flowing through all resistors is identical.

@cosinekitty

In circuits like this, where you are driving a bunch of LEDs as a unit, I have found that you don't need a dedicated resistor for each LED.

Yep, I know it looks tempting to just use one resistor for all the LEDs. One resistor works great, but if the voltage drop of each leds is significantly different, some won't light, or will hog more current; when one burns out or goes 'open' then the others take up its unused current.

I saw someone do this only last week with a dozen expensive blue leds, that were slowly dying like they had some kind of virus! This has particularly comical effects on a breadboard, when you decide one led isn't working, and try to replace it...

@dumptyhumpty

That's good I can get that stuff at Radio Shack

Sorry, I was kidding about RS: you should try to avoid them at all costs! Try a local store instead of corporate if you can, it's almost always a lot cheaper... my local supllier will sell me 100 1% resitors for $1 CAD, whereas Radio Shack want $2 for five. Suport small business if you can-- it's the Arduino way!

Would it be ok to use these prewired LEDs?

thise are 12V leds, with integral resistors.. you would neeed a separate 12V power supply for them, but sure they'll work. You could power the Arduino from the same 12V supply. For something expensive like super-bright led's, you might want to try Digikey.

Hey Daniel,

Points well taken. I have used this trick myself in a little pantry light I made for myself: it uses 4 very bright yellow LEDs. (I used a 555 timer chip in monostable mode so that the LEDs stay on for 1 minute, then turn themselves off.) Before rigging them all up to share a resistor, I hooked them all up independently and measured the current drain, and they were very nearly identical. The resulting pantry light has worked just fine for the past 2 months, and to look at them, I cannot tell any difference in the brightness. I also felt the leads coming out of each LED and could not notice any heat, so I'm not worried about them burning out.

But, your warning is exactly right. And, considering that resistors are dirt cheap, it's probably safer to go ahead and give each LED its own resistor.

Sorry, I was kidding about RS: you should try to avoid them at all costs! Try a local store instead of corporate if you can, it's almost always a lot cheaper... my local supllier will sell me 100 1% resitors for $1 CAD, whereas Radio Shack want $2 for five. Suport small business if you can-- it's the Arduino way!

Ok no problem, I can probably find one around here. Actually Sparkfun seems to have them and there not to expensive.

thise are 12V leds, with integral resistors.. you would neeed a separate 12V power supply for them, but sure they'll work. You could power the Arduino from the same 12V supply. For something expensive like super-bright led's, you might want to try Digikey.

So will they not work because of the resisters? How would you wire it up for a 12v source and still use the Arduino? Also does any one know how I could water proof the leds (and their wiring) . They will be in a spot that they might get wet.

The leds you linked to are prewired with a resistor for 12V, so they would be very dim on a 5V supply. Also, they take 80 milliamps each, so if you have a bunch of them, you would need a separate power supply, as the 5v suply on the Arduino is good for about 400ma of external power. If you use those 12V leds with built-in rsistor, you'll need a separate power supply adequate to the task... for ten leds, get a 12V 1A supply, for 20 leds, get a 12V 2A supply, etc. The 2N2222 transistor could switch 10 or so of the 80ma leds safely.

Your 12V supply would go to

the + connection of the leds being switched by the transistors, and the Arduino's balck power jack, which takes a range of voltages and converts it to a stable 5V for the Atmega8.

D

Thanks for your help. Now it's time to just get every thing and figure out the waterproof issue.

try soldering the led connections, then cover them with heat shrink tubing and then silicone. Not very environmentally friendly, but it will be waterproof.

I found these from a friend: http://www.oznium.com/blaze-1foot and it looks like I can just modify the plug and they will work. Expensive though!

yep, just remember that a small transistor like the 2N2222 will only drive up to an ampere's worth of LED's before the transistor dies a silent death. For a high-current load like those LED 'sticks', you may need something like a TIP102, wich will drive a whopping 8 amps (with a heatsink, of course).

D

yep, just remember that a small transistor like the 2N2222 will only drive up to an ampere's worth of LED's before the transistor dies a silent death. For a high-current load like those LED 'sticks', you may need something like a TIP102, wich will drive a whopping 8 amps (with a heatsink, of course).

D

They draw 100ma each so the 2n2222 can drive them right? I still need to give them 12v though.

sure just add up the current load, and as long as it is well under 1A, use a 2N2222, for much more you might want to try the TIP102, as it will carry more current and it has a heat sink built-in.

sure just add up the current load, and as long as it is well under 1A, use a 2N2222, for much more you might want to try the TIP102, as it will carry more current and it has a heat sink built-in.

Thanks I love how your always on late (for me anyway). You made it sound like you had to add the heatsink to the TIP102 thats nice it comes with it. I'm just having trouble figuring out if that led tube will mount how I need it to.