# Trying to understand the limit of ma for the Leonardo pins

Hello,

I am a little confused about how the ma works for the Leonardo pins with LEDs. I have serveral RGB common cathode leds. According to the datasheet:

Color Red Green Blue
Voltage 2.0 3.2 3.2
ma 20 20 20

From what I am reading about the pins, each pin can only handle 40 ma. Does this mean that one pin can only power two colors of the RGB? If so, does this mean that I need an alternative power source for the LEDs? In total, I am looking at powering between 10 to 30 (200ma to 600ma) RGB LEDs.

That's a lot of RGB LEDs - and x3 for current, as each LED with all 3 colors on is 60mA.
You're better served with a chip like WS2803 to control 6 LEDs each (18 IO) and have PWM control of each signal.
'32U4 can only sink/source 400mA of current, and there are limits to how the 20mA per IO pin is spread over the ports, see Section 29, Notes 3 & 4 from the table:

Note:

1. "Max" means the highest value where the pin is guaranteed to be read as low

2. "Min" means the lowest value where the pin is guaranteed to be read as high

3. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
ATmega16U4/ATmega32U4:
1.)The sum of all IOL, for ports A0-A7, G2, C4-C7 should not exceed 100 mA.
2.)The sum of all IOL, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA.
3.)The sum of all IOL, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA.
4.)The sum of all IOL, for ports F0-F7 should not exceed 100 mA.
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.

4. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:
ATmega16U4/ATmega32U4:
1)The sum of all IOH, for ports A0-A7, G2, C4-C7 should not exceed 100 mA.
2)The sum of all IOH, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA.
3)The sum of all IOH, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA.
4)The sum of all IOH, for ports F0-F7 should not exceed 100 mA.

Would I have to run the voltage through a digital potentiometer after the WS2803 or would I be able to control the voltage comming out of it? If I do still need a digital pot, could I run multiples of the same color through it as long as the ma does not exceed the maximum of the digital pot or would I need one for each output pin? If I do need to use potentiometers, could I skip the WS2803 and run them off of an external power source? Sorry about all of the questions...

Would I have to run the voltage through a digital potentiometer after...

No. With PWM, you don't control the voltage. PWM switches on & off rapidly. It it's off most of the time it's dim. If it's on most of the time it's bright.

I don't know what typical power ratings are for digital pots, but you'd probably run into similar current limits and you'd have to use several digital pots. PWM is the way to go.

Digital potentiometers have absolutely nothing to do with operating LEDs, Simple as that. They are for a totally different purpose.

You need to control the current through the LEDs, not voltage; if we are talking 20 or 30 mA, then you generally use resistors while for high power LEDs, you use a current control circuit not because it is more efficient which it is not unless it is a full switchmode power converter, but to make it stable as the LED heats.

Next you may want to control the individual brightness rather than simply switching the LED on or off. As it is generally rather complex (and expensive in quantity) to arrange to vary the current of your constant-current driver, this is generally performed by PWM - switching the LED on for a varying duty cycle at a rate exceeding 100 Hz so the flicker is not visible.

Finally, you do not rate ATmega (or microcontroller pins in general) at more then 20 mA and even then, there is a group total which means you do not rate them as more than about five or six simultaneously at 20 mA each.

This means that if you desire full brightness of more than five LEDs, you look for an alternative purpose-designed driver chip. The various WS28xx chips are designed to perform all these tasks for you - current limiting, PWM brightness and control of multiple channels per chip to their full rating. They completely solve your problem, you just wire them to the power supply (which is probably not connected to the Arduino unless it is well regulated - once you go over a dozen non-multiplexed LEDs, you cannot power them through the Arduino) and write the code (use the libraries) to operate them. The only other components you need are bypass capacitors for each chip.