Arduino mega or shift register for 40 LEDs all on/off or individually on/off

First time poster, new arduino user but used others through my years, opinions and suggestions appredicated:

Initially I will need to control a 4 x 10 led grid very low current LEDs using a powersupply. I will need to do any of the following and would prefer to use the mega unless shift registers are suggested otherwise:

All LEDs on at once, off at once
Dim blocks of LEDs (10, 20 at Once) while others stay on
Flash/blink all at once, many at once, or rows one at a time
Individual on/off while others remain in same state
5 inputs will be read and will determine the display pattern

I'm hoping the Mega (54 output?) can cover this because I plan to constantly change the sketch for different light displays and it seems easier to change a pin output (40 of them) than to figure out what to pass off into a shift register. Size is not a c

I'm asking in advance before I begin this project so I can program according to using shift registers or not.

40 LEDs @ 20mA per LED gives a total current of 0.8A.
That is too much to be supplied by a Mega so you either need external drives on the mega or you need to use a shift register or two.

"40 LEDs @ 20mA per LED gives a total current of 0.8A.
That is too much to be supplied by a Mega ..."

Not necessarily. Just need to spread the 800mA over the IO ports.
Note that not all ports are actually brought for use, so need to plan around that some.
I would use high brightness LEDs (like 4000-5000mcd) and run at lower currents to provide some margin.
For example, a 10,000mcd white LED is still blindingly bright at just 2-3 mA.

Per 2549N–AVR–05/11, Spec sheet to ATMega2560:

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.

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.

Not necessarily. Just need to spread the 800mA over the IO ports.

And the current limit on the power pin?
That's 200mA.

I'd use shift registers of some sort, probably 4 x TLC5940. If you write a function to keep the LEDs updated from a 40-word array, then you can reprogram the display just by changing the data in that array.

I didnt want to get too detailed about the project but power and current is not a concern. I will likely be using some form of transistor setup or a buffer chip to actually power all the leds with the arduino only needing to supply the actual led condition. So, assuming Ive already blown up several "basic stamps" years ago and now am capable of protecting the arduino, can the arduino run a matrix of that size without getting glitchy? lol

I was looking at the Max7221 chip (is this overkill?) for use with a standard UNO to do the same but again, I was hoping for just the MEGA to keep things simple program wise.

I'll look into that tlc5490

If I wanted to dim 20 leds and blink 10, and off the other 10..is that easier with just the mega or would you guys still recommend using other chips ? Would it actually be faster for the arduino to shift 40 leds statuses (lets assume some are to appear dim so Id pulse them on/off a few times per second) than to just have the MEGA go through a loop thats controlling the individual outputs?

To add details, Id also be scanning 4-6 inputs for simple button status which will then determine the LED output display pattern.

Thanks in advance.

"DC Current VCC and GND Pins................................ 200.0 mA"

4 Vcc, 4 Gnd pins - I interpret this as the chip can handle 800mA of total current, just has to be spread over the port as noted.

Planned usage is changing too fast for me ...

We have had various attempts at finding out if that is true from Atmel but nothing has been received yet. Even so four pins at 200mA is 800mA with nothing left for anything else.

I agree though about changing use or drip feeding information is not helping the op get a real answer.

Answers are only as good as the questions.

If you only need to control the LEDs in 4 blocks (i.e. all the LEDs in each block of 10 always do the same thing), then the simplest solution is just to use 4 of the PWM-capable output pins of an Arduino, each one driving a BC337 transistor through a 470 ohm resistor, and connect 10 LEDs (each with a series resistor) between your +ve supply and the collector of each transistor. If your +ve supply voltage is high enough, you may be able to connect 2 or more LEDs in series with each resistor, saving on current and series resistors. You don't need a Mega for this, a Uno will do.

I'm sorry for the lack of design facts but my question was focused on the processing ability of the mega and not the power limitations. I understand that you're all being as helpful as possible with my limited details, I was trying to keep it as focused as possible. My external circuit could be 40 LEDs, 40 solenoid valves, or 40 motors :slight_smile: I do appreciate the info about output limitations and I should have stated that I'd ask about that after I get past this first original question.

I've read many of your posts grumpymike and crossroads ,and your words are like gospel. If I should be more specific in the future please get me in check

OK let's look at your initial request:-

All LEDs on at once, off at once
Dim blocks of LEDs (10, 20 at Once) while others stay on
Flash/blink all at once, many at once, or rows one at a time
Individual on/off while others remain in same state
5 inputs will be read and will determine the display pattern

If you need to dim the LEDs in blocks but need individual control over them then your requirements are:-
read 5 inputs
individually control the brightness of 40 LEDs

The rest is just duplication and obfuscation.

Coupled with the fact that you don't want to source the LED current from the arduino I would say you would have to either:-

  1. Implement a software PWM for the arduino to allow all pins (or at least 40 of them) to have individual PWM outputs.
  2. Use a simple shift register (5 of them cascaded) and implement the PWM in software like in the shiftPWM library
  3. Use a chip that will give you a PWM output like the TLC5940 or the PCA9685. As these handle 16 outputs then you will only need three of them.

So those are your options, choose what you are most comfortable with.