16 LEDs Powered from Arduino Mega 2560

Hi, I’m wondering if I can safely power 16 individually LEDs from my Arduino Mega 2560. I’ve read on other sites that there is a 40 mA max per pin and 200 mA max total. So if my LEDs were drawing 20 mA each, would I not be able to power 16 as that would be 320 mA total? I also have an RTC being powered by the board. My project is to have 16 LEDs turn on an off at certain times of the day. I’d prefer to have it all powered via the board plugged in via USB and I’ve also seen that I could draw up to 800 mA if I use each of the GND and VCC pins together, but I would need help on how to do that so I don’t fry anything

Thanks again, I’m still new to this electrical stuff and terminology so some clarity would be helpful.

*Edit: Sorry, I should have been more clear. I am just using 16 5mm white LEDs and wish to control each of them independently. I am also using an DS3231 RTC and I assume that would need some current set aside for it.

The 40 mA max per pin applies to the IO pins on the microcontroller. But it's very unlikely you would power an addressable LED strip from an IO pin. The IO pin(s) are only connected to the data line(s) of the LED strip. The data lines don't power the strip, so there is no problem with getting anywhere near 40 mA on the IO pin(s) connected to the data line(s).

Note that each individual LED can draw somewhere around 20 mA (if you measure, I think you'll find it's a bit less than that). There are three LEDs per addressable RGB LED. So if each LED is drawing 20 mA max, the maximum current of your 16 addressable LEDs is 20 x 3 x 16 = 960 mA. You won't get that from a USB port. So if you want to be able to run the whole strip at full brightness, you should use a separate power supply for the LEDs.

Many ‘simple’ LEDs are bright enough at 5mA.

What LEDs are you using?

Yes you can power the Mega from the 5 volt Vcc pin with an external 5v power supply.

When doing so, avoid using the USB plug going to the PC.

For addressable LEDs, (5 V) never comes from the Arduino, it comes from a regulated 5 V power supply of adequate current capability - 60 mA per addressable LED. You then use the same supply to power the Arduino via its "5V" pin.

larryd:
Many ‘simple’ LEDs are bright enough at 5mA.

What LEDs are you using?

Yes you can power the Mega from the 5 volt Vcc pin with an external 5v power supply.

When doing so, avoid using the USB plug going to the PC.

I am just using 5mm white LEDs, I need to be able to power each of the 16 on and off throughout the day.

The AVR chips have various limits in terms of current. I think I read that for the atmega2560, there is a total current of 400mA, but unfortunately there are limits for various groups of pins and ports which can be as low as 100mA, so not enough to drive 8 leds @ 20mA each. So it can be done with care and reference to the chip's data sheet, so that the current is spread over the pins & ports so as not to exceed any of those lower limits.

But I'm not sure you realise or understand what larryd was suggesting. When an led is specified at 20mA, this is the maximum, not the minimum. It will run fine at lower current. It will not be as bright, but you may well find it to be too bright at 20mA anyway. At 10mA, the leds will not look as bright, but probably still bright enough, and their life will be extended and the arduino will not be overloaded.

Leds don't last forever. The more current, the more quickly they fade over the long term. To make them last longer, you need to use a much lower current than the maximum, so that the fading effect is only small, even after several years.

You should be able to do this.

Most modern LEDs give enough light at 5-10ma.

If you want to drive more current through a LED you can use a drive transistor.

Use transistor circuit Q1 in this image if you want more current to flow.

Adjust resistor R11 to set the current.

Atmega2560: 800mA, 200mA per Vcc pin, with port limits as listed in the datasheet.
USB won't supply that much, onboard regulator likely to overheat if barrel jack voltage is high.

Or add two tpic6c595, or 6b595, drive with 3 pins from arduino and then can sink lots of current.

PaulRB:
The AVR chips have various limits in terms of current. I think I read that for the atmega2560, there is a total current of 400mA, but unfortunately there are limits for various groups of pins and ports which can be as low as 100mA, so not enough to drive 8 leds @ 20mA each. So it can be done with care and reference to the chip's data sheet, so that the current is spread over the pins & ports so as not to exceed any of those lower limits.

But I'm not sure you realise or understand what larryd was suggesting. When an led is specified at 20mA, this is the maximum, not the minimum. It will run fine at lower current. It will not be as bright, but you may well find it to be too bright at 20mA anyway. At 10mA, the leds will not look as bright, but probably still bright enough, and their life will be extended and the arduino will not be overloaded.

Leds don't last forever. The more current, the more quickly they fade over the long term. To make them last longer, you need to use a much lower current than the maximum, so that the fading effect is only small, even after several years.

Would you have any idea which pins I can spread my 16 LEDs over to have them be controllable and as bright as possible (important for my purpose) and be within the max current draw?

No idea, sorry, I have not memorized those figures. They are written down in the data sheet so you don't have to.

Here you go:

  1. 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:
    ATmega640/1280/2560:
    1.)The sum of all IOL, for ports J0-J7, A0-A7, G2 should not exceed 200mA.
    2.)The sum of all IOL, for ports C0-C7, G0-G1, D0-D7, L0-L7 should not exceed 200mA.
    3.)The sum of all IOL, for ports G3-G4, B0-B7, H0-B7 should not exceed 200mA.
    4.)The sum of all IOL, for ports E0-E7, G5 should not exceed 100mA.
    5.)The sum of all IOL, for ports F0-F7, K0-K7 should not exceed 100mA.
    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.
  2. 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:
    ATmega640/1280/2560:
    1)The sum of all IOH, for ports J0-J7, G2, A0-A7 should not exceed 200mA.
    2)The sum of all IOH, for ports C0-C7, G0-G1, D0-D7, L0-L7 should not exceed 200mA.
    3)The sum of all IOH, for ports G3-G4, B0-B7, H0-H7 should not exceed 200mA.
    4)The sum of all IOH, for ports E0-E7, G5 should not exceed 100mA.
    5)The sum of all IOH, for ports F0-F7, K0-K7 should not exceed 100mA.

(From page 43 of the data sheet)