Multiple LEDs powering?

Hello everyone,

I'm new to arduino and electronics (though, have read some theory about some components). I ordered an Arduino Mega 2560 Rev3 a few days ago, also a breadboard, wires, and 100 LEDs (together with resistors).

I think what I'll start with will be playing around with them, later maybe buying some more stuff.

I have a few questions (couldn't find clear answers anywhere);

I want to control as many LEDs as possible individually as possible. I've heard of charlieplexing, looks too complicated for me. LEDs I ordered:

I can power it either through USB, or through the barrel plug from a 9V battery. I think I can just wire them like: Arduino Digital (OUT) -----> resistor ------>LED-------->Arduino GND (correct me if wrong) With a resistor, single LED would drain 20mA. I've heard every pin outputs up to 40mA. Is there any total max? Some weird forums mentioned the max is 200mA, if true, that would mean my limit would be 10 LEDs on 10 pins... :(

How much current can the 5V out provide? If I understand it right (saw this answer somewhere), it can provide 400mA when USB and even more from 9V plug? Then maybe its possible to wire up like:

-----------> resistor ---------> LED1 --------> Digital (IN) at low/high (which one to use to turn it on?) 5V out ---| -----------> resistor ---------> LED2 --------> Digital (IN) (other one)

(please correct if wrong)

Also, I have a portable 20000mAH battery with 2 usb ports (1A and 2.1A). Is it suitable to power arduino somehow?

Any other suggestions? What I'm trying to do is controlling as many LEDs as possible individually, also with ability to have them all turned on at the same time. Any help is appreciated!!

Thanks in advance, Robert

The cumulative maximum is spelled out in the datasheet. 200.0 mA going in (Vcc) or out (Gnd).

If you want to control the maximum number of LEDs you will want to power them separately.

Do you want to control the brightness of each LED or just on/off?

Do you have to have all the LEDs on at the same time or would it be sufficient for the LEDs to appear to be on at the same time? You can use multiplexing to control more LEDs with less maximum power draw.

Is it OK to use components other than resistors and LEDs? There are driver chips for controlling 16 (with brightness) or 64 (on/off) LEDs.

I need only on/off. I don't want to buy anything more if possible... Any help?

Well, without additional hardware you shouldn't draw more than 200 mA. You could run your LEDs at lower power and light 20 of them at 10 mA. Just adjust the resistor to lower the current flow. You can try different current levels to see how much current is 'enough'. If 5 mA is enough you can run 40 LEDs.

What about the 5v out? Doesn't it give 400mA? If it does, how to wire to it so I control the leds through digital individually?

What about the 5v out? Doesn’t it give 400mA? If it does, how to wire to it so I control the leds through digital individually?

You can draw about 400 mA from the +5V pin (using USB power) but if you are grounding it through Arduino pins the total can still only be 200.0 mA. The 200.0 mA limit is for current THROUGH the chip. That means current sourced (from Vcc) or sunk (to Gnd).

I'm confused... What do I need then, transistors? (Looking for the cheapest solution)

I’m confused… What do I need then, transistors? (Looking for the cheapest solution)

If you had transistors you could use 8 pins to source power and use transistors to sink up to 8 LEDs at a time. By multiplexing you can light 8 LEDs per transistor for as many pins as you can spare. The Arduino MEGA has 54 digital output pins so you can have, in theory, 46 rows of 8 LEDs. I don’t know if you can switch between rows fast enough to refresh all 46 rows in under 1/30th of a second.

How do I multiplex? Can you give me the scheme? Also what transistors to use? And how to program then, for example, a program that fills up a row of leds (fills by showing a row out of lit-up leds which is getting longer) 1 led a second?

How do I multiplex?

I would not do that as a first project but this is what it is all about.
It is generally used with a matrix of LEDs and involves flashing the LEDs on and off so quickly it looks like they are on all the time all be it dimmer. Multiplexing is similar to charlyplexing which you say is too complex for you at this time.

Idk, I get the idea of the charlieplexing, the complicated thing is the wiring when there are more leds. What about dim? Why would they be dimmer?

Why would they be dimmer?

Because they are only on part of the time. If they spend only 10% of the time on they are only going to be 10% of the brightness. Subject to the eye's brightness perception law.

Which gives better results; charlieplexing or multiplexing? So as I understand there is no way I could control more than 20 led 10mA each without multiplexing?

Also: if the matrix is 10 rows and 20 columns, by scanning columns, I would fit in the maximum (10 leds 20mA each) which could be on at a time and would not require additional hardware parts. Right?

Which gives better results; charlieplexing or multiplexing?

What do you mean by better? It is just different. Basically you can control more LEDs with less hardware using chalyplexing but the software is a bit more complex.

which could be on at a time and would not require additional hardware parts. Right?

Wrong. With a 10 by 20 matrix being multiplexed you would arrange things so that a whole row or column is on at any one time so you need some current drivers. If you only had one LED on at a time each LED would only be on for 1/200 th of the time or 0.5% and so would be very dim indeed.

Ok… Can you then tell me: how many maximum leds can I control individually without any additional parts, having the following:
Arduino mega
830 point solderless breadboard
65 variuos lenght wires
Usb/9v battery power supply
100 leds (5 colors, 20 of each)
Resistors (I don’t know their values, they come with the leds)
Also, how do I do that…

Can you then tell me: how many maximum leds can I control individually without any additional parts,

No. It is not a simple question with a simple answer. It depends on how you wire them, how you drive them and what current you want to run them at.

If they are multiplexed, charlyplexed or simply connected to the the output pins. It is not like going into a shop with a fist full of coins and saying to the shop keeper what can I get with this. The answer is complex. And if I plucked a number out of thin air would that really help you? Because I would also have to specify how you wire it up and how to drive it. So you are asking me to do over an hours worth of work without convincing me you are going to do anything with the answer.

I was just asking for any way... I'd like to have a matrix of leds that could be coded for some effects, as large as possible, without any additional components. Current? They can take up to 20mA, but I'd prefer more leds than greater current for each, so 10mA would be enough. Wiring? Would be great to fit on the board... Charlieplexing, multiplexing are okay as long as they don't make the leds less than 50% as bright as normal power... I don't ask for lots of ways, all I need is to find an optimal one... Can you help me with that?

Its kind of confusing, because there are several limits within an arduino, and all arduinos are not the same. My current understanding (and this may change...) is that among the 328 chips (like on an uno, or nano) there are 28 pin dips, and 32 pin qfps. the 28 pin chips have one VCC, and 2 GND.

So, with a nano you may be able to source up to 400ma, depending on other factors mentioned below.

The bigger duinos (like the mega,) have more VCC pins, and I think one of them is capable of upto 800ma, assuming other conditions are also met.

There are 2 other current limit factors, there is a 40ma limit on any individual pin, and each port (a group of pins), have individual limits for sourcing, and sinking. In theory, you could source on some pins, and sink on other pins, and still be within safe limits.

Now, If you are trying to come up with one answer for all situations, the easiest safe answer is 200ma.

To make matter a bit more complicated, these ratings are more like best use ratings, they are no guarantee that you will break anything (like a fuse). in fact you may exceed levels without even knowing that you are.

I have never used a mega, but anyduino can handle upto 200ma, which you could easily do with a 10x10 matrix, using 10 pins to source, and 10 pins to sink. This is a pretty common mulitplex. You could further reduce the pin count with charliplexing, but having different color LEDs makes that a little more difficult, and imposes some constraints that you dont need.

A 10 x 10 matrix that lights up to 10 LEDs at a time (like the above mentioned one) will give you a 10% duty cycle, which wont be as bright as full on. You could even run them one LED at a time, which would really reduce the current use, and make it dimmer, and slower, but another option.

Since you have a mega, you have higher current limits than a uno, you may very likely be able to make a much brighter display by reducing your duty cycle. The more LEDs you can light at one time, the brighter, and faster your display will work. But it has to keep everything within their prospective limits to be a safe design. If you exceed any one limit, you may risk damage or excessive wear, but there is no guarantee.

You can also avoid figuring out these limits by adding parts (like shift registers, or LED drivers), but the more parts you add, and the types of parts you add, the more chances for failure you build in.

If I were you, I would use those 100 LEDs and see how many ways you can hook them up. make a matrix with some of them, make a small charlieplex with some other ones, then make a cube or other 3d shape with them.

With 64 LEDs 4 resistors and an uno, you can build a 4x4x4 LED cube (light only 1 LED at time), add a few parts and you can light 16 LEDs at a time. You can start with one thing, and re-do it many times, each time learning something new.

From what I've seen on the spec sheet, you have 54 digital I/O pins. That means they are either on or off. Without regards to brightness, you should be able to control 54 LED's with these pins as long as you don't need to communicate with any other equipment.

Now, if you are running 54 LED's, then the current draw will become an issue. The 20+ milliamps stated is typically maximum at a certain temperature, certain voltage, etc. From my own testing and verification with a voltage and amperage meter, I'm seeing far less real world actual draw than that. Still better to be safe than sorry though.

14 of the I/O pins on the Mega can do PWM. Basically a high frequency signal that blinks the LED faster than a person can visually see and turns it on or off for short periods to control the brightness. So you could run 54 LEDS and control the brightness via code on 14 of them. The rest of the LED's would require different resistors to control the brightness. You could run the tone function to make things blink and do some fancy coding to mock PWM on pins that don't normally do it, but it's kludgy and if you don't know how to code well it could become a nightmare.

The real question is, what are you trying to do and why do you want to do that? Maybe there's a better method?