How many LEDs can you PWM?

I’m looking to PWM about 15 leds for a project. The LEDS are standard 5mm 2.0 v 20 mA yellow leds. I want to wire 3 or so leds in parallel for each Arduino pin with a 200 ohm resistor on each led. Most of the time I don’t expect them to be at full brightness, but somewhere in the middle to high end range. How many LEDs can I put on each pin without damaging the Arduino?

Thanks.

The absolute maximum rating for an Arduino output pin is 40 milliamps. At full brightness you could use only two of your 20 milliamp LED's per PWM pin. You can run three LED's at 13 milliamps each on each PWM pin or you can use a transistor per pin for current switching and get full brightness on quite a few LED's.

Pauly:
I’m looking to PWM about 15 leds for a project. The LEDS are standard 5mm 2.0 v 20 mA yellow leds. I want to wire 3 or so leds in parallel for each Arduino pin with a 200 ohm resistor on each led. Most of the time I don’t expect them to be at full brightness, but somewhere in the middle to high end range. How many LEDs can I put on each pin without damaging the Arduino?

Thanks.

This page:

http://www.arduino.cc/en/Reference/Board

says 40mA per pin max, so you are getting quite close. If I were you I'd drive your leds with a transistor with a higher amps rating. Connect the base of the transistor to the pin. There must be many examples in these forums of how to do this.

Thanks for the replies.
I was hoping to avoid using a transisitor, but have done that before.
I'll try the transistor, I should have some 2n222s lying around.

Assuming you're running your Arduino at 5V and since your LEDs are only 2V you could try wiring two of them (and a resistor) in series and see if they're the right brightness. Then eventually two strings in parallel on each pin for a total of four LEDs per pin.

It's pushing that 40ma limit but... y'know.

   ---LED---LED---resistor---
--|                          |--
   ---LED---LED---resistor---

Or use a ULN2803 if you have one to drive the LEDs.

I had some 2n222 transistors and got it to work.
What you see here is two transistors powering 4 LEDs each.
Now to figure out the best way to wire it up.

Thanks again.

Check the current flow on those with a multimeter - they don't look very bright.

CrossRoads:
Check the current flow on those with a multimeter - they don't look very bright.

From the close-up picture it looks like there is one current limiting resistor for all four LED's in a group. I'm pretty sure that each LED should have a separate current limiting resistor. If the resistor is chosen to provide 20 milliamps then, the way it is wired, the four LED's have to share the 20 milliamps rather than each getting 20.

I have lowered the resistor value and now used one resistor on each led. Much brighter.
Thanks guys.

Newbie question: Is it necessary to add Rb (base resistor) when using a transistor as a switch? Could omitting Rb cause 40mA to be exceeded through the output pin?

andyjjones:
Newbie question: Is it necessary to add Rb (base resistor) when using a transistor as a switch? Could omitting Rb cause 40mA to be exceeded through the output pin?

A base/emitter junction of a transistor works much like a led in that once the voltage increase above it's forward voltage drop (around .6 vdc for a NPN transistor) the junctions turns on and acts much like a short circuit to ground. So yes the series base resistor is required and should be sized to limit current draw from the output pin to around 20ma or less. Then the base current times the current gain of the transistor (beta) determines the maximum current that can flow from the collector to the emitter (and on to ground).

Lefty

"Could omitting Rb cause 40mA to be exceeded through the output pin? "
Once the transistor turns full on, the series resistor will limit the LED current.
So you need the base resitor to protect the arduino pin as Lefty says, but the series resistor is usually the force for the current limit.

You can take some measurements and determine what current you are really getting thru the parts.
5v source, 2V across the LED, 0.7V across the transistor, rest is across the resistor:
(5-2-0.7)/Resistor = current flow.
Or just put your multimeter in mA measurement mode, and the probes in series between the LED and the current limit resistor.

take a look here for details, AND check the per PORT limitations as well as per PIN limitation:
http://arduino-info.wikispaces.com/ArduinoPinCurrent

...thanks to Crossroads and others for help with this...