# Mega: LEDs on 50 digital pins HIGH @ same time

Hello. I have an Arduino mega. Let's say I add an LEDs (2v drop each, 20mA) to 50 of Arduino's digital pins and digitalWrite(x, high) all of them at the same time. 1. Will the LEDs light up? 2. Will this kill my Arduino? 3. Is the 40mA limit per pin or global?

I searched the forum but did not find a clear answer to this question. Thanks a lot in advance.

HEMOglobina

Total package current limit is 200ma, so 20 LEDs @10ma (or 10 LEDs @20ma) each is probably the maximum. To drive 50 you would have to utilize an external power supply and switching transistors. Also each LED will require it's own current limiting resistor.

Lefty

Also each LED will require it's own current limiting resistor.

only to achieve max brightness per each individual LED

Thanks guys. What made me wonder was this tutorial by Tom Igoe (http://www.tigoe.net/pcomp/code/category/arduinowiring/424). In the first sample program (step 3) he lights up 64 LEDs with no remorse. What am I missing?

By taking Tom Igoe's example, in case a decide to use transistors, I have to place them in the columns (LEDs anodes), right?

Thanks a lot, LG

there is only 1 led on at a time, and there's a silly notion if you only turn on a led for very short amounts of time it will not die (it will it just takes a heck of a lot longer, but with no restriction your doing damage, all be it breif damage, to both the arduino pin and the led)

if you use transistors you would need them on both the rows and columns in order to turn on any led at a given XY coordinate

He is not turning on just 1 LED, but all of them in the first example. From his own words:

“The first program I wrote was very simple; it just turned on all the LEDs, like so”

I tried it here with a 3x3 LED array and my Arduino’s Atmega got quite hot after a while…

Take a look at this schematic

replace the shift register with 8 digital output pins, in this configuration (basically LED's in parallel) I used 1 resistor per row, when 1 led is on at a time (matrix drawing mode) the led is running at 20 ma, when the entire row is on each row is restricted to 20ma, which dims every LED in the row, to get around that each LED needs its own resistor

make sure you have a sturdy power supply, a external 5 volt regulated source would be required, if all are on and getting their max current.

Problem is that Tom wrote a goodish book on networking, communication and interfacing and as a result he thinks he is an electronic engineer.

There are many things he doesn't understand, like how a GPS system works (see his book for a completely wrong explanation of what is happening). This is another case of him being wrong, by thinking you can run an LED matrix from an arduino without any current limiting resistors. See this for the real story:- http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

I read somewhere that different ports on the Mega can take a total of different current per port… for example (these are probably wrong… just an example)
PORTK can take 200ma
PORTB can take 100ma
PORTA can take 100ma

And these are all together, as a total?

I could be wrong as a total, but I know I read that different ports can take different amount of currents.

I know I read that different ports can take different amount of currents.

Yes they can but the Total of all pins must not exceed 200mA.

the data sheet says:-

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 200 mA. 2)The sum of all IOH, for ports C0-C7, G0-G1, D0-D7, L0-L7 should not exceed 200 mA. ICC ATmega640/1280/1281/2560/2561 3)The sum of all IOH, for ports G3-G4, B0-B7, H0-H7 should not exceed 200 mA. 4)The sum of all IOH, for ports E0-E7, G5 should not exceed 100 mA. 5)The sum of all IOH, for ports F0-F7, K0-K7 should not exceed 100 mA. If IOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current greater than the listed test condition.

Problem is that Tom wrote a goodish book on networking, communication and interfacing and as a result he thinks he is an electronic engineer.

Indeed. I have both his books. "Physical Computing" is my bible at the moment. Good to know that I should not trust everything I read. Sometimes I forget about that :) Thanks a lot Grumpy_Mike. Really like your website and posts here at the forum.

@Osgeld: Thank you for the schematic. Is it from an Instructable done by you? Could I have the link to the Instructable please? Based on this Instructable (http://www.instructables.com/id/810-LED-Matrix-with-4017/) I thought I did not need transistor for both rows and columns. I guess I was wrong.

Kind regards, LG

http://www.instructables.com/id/The-74HC164-Shift-Register-and-your-Arduino/

and you dont need a transistor on both if you dont plan on switching columns, with the transistors on both ends all higher currents are not driven tru either chip, but again if your not interested in XY points you dont need both

http://www.instructables.com/id/The-74HC164-Shift-Register-and-your-Arduino/

and you dont need a transistor on both if you dont plan on switching columns, with the transistors on both ends all higher currents are not driven tru either chip, but again if your not interested in XY points you dont need both

Nice Instructable Osgeld. Thanks a lot for sharing. I did not quite follow why you need the 1Kohm resistor to the base of a NpN transistor. I just tried with the Arduino (withouth the shift register) and it worked without this 1kohm resistor (in fact i just noticed it after I had already assembled the circuit :).

Thanks! LG

you need it there to limit the current from the output to the transistor

in that schematic there is also a 150 ohm resistor after the transistor, thats actually a mistake on the schematic, if it wasn't there you would have burnt up the transistor in a short moment (like 3 seconds the base of a transistor cant handle much) the 150 ohm is limiting the flow to 20ma, and could slowly cook the transistor to death from base to emitter. (as i think base current on a 3904 is 10ma)

Also 74HCxx logic series IC's usually only can source 16-20ma (general rule that somehow stuck in my brain feel free to debate, and depending on the exact chip) so 1 row would have been pushing the limits, let alone turning on all 4

• there is no restrictions on the cathode side, so it would have dead shorted the signals to ground, in fact take a continuity meter to the base and emitter, they are connected

Oh and thanks, I am not really all that enthused about that instructable TBH :-[ , Ive had better

The instructable you posted is valid, but each collumn of led's will be restricted to 20ma

I just had my head jammed up my bum, with my setup transistors on both axis is needed to keep within the tolerances of the chip and evil plan B is to be able to use it with 3.3 volt logic signals (provided you supply it with 5 volts or change all the resistors)

OR if you plan on turning on all 50 led's on at once at their rated current

To make things simple and since I have a mega, I decided to give up on this multiplexing thing for the moment, so I assembled the following test circuit (I'm aware that I don't have control of the individual LEDs at all, but I just want to light up groups of 3 or 4 LEDs):

To my surprise the LEDs did not light up when I set the pin as HIGH (even by using a 12Vdc supply). The transistor is a 2N3904. So I removed LED by LED until there were only 2 left and they were barely lit. So I measured with my multimeter and only around 5v was going across the transistor. Why is that? What am I doing wrong?

Thanks a lot for all the help you are providing me :) Kind regards, LG

are you limiting the current going into the led's? (in that image it does not look that way, and your going to need to)

is the transistor connected right? in the image its backwards

http://www.fairchildsemi.com/ds/2N/2N3904.pdf

Also, led's wired in series is a whole different ball of wax than the parallel examples you have been looking at

That diagram is not right. You need to connect the LEDs between the collector of the transistor and the +12 supply. The emitter needs to be connected to ground.

Look at the circuit here:- http://www.thebox.myzen.co.uk/Workshop/Motors_1.html And replace the relay coil with the series LEDs. Also put a resistor of at least 100R in the LED chain.

Yes, indeed I put it backward in the drawing above, but not in my circuit. Sorry about that.

I have just found out that I know nothing about transistor and I'm going crazy here. I'm trying to assemble the circuit from your instructable, but without multiplexing (meaning I will have one LED, actually 4 LEDs, per Arduino PIN), so this is what I'm planning on doing: What is wrong with this?

My biggest surprise was to do this: and see that the LED lit up!! How is that possible?!

Thank you once again for your help, LG

Hello Grumpy_Mike. You posted while I was typing mine :) I will try right now what you posted. Thank you.

If it isn't too much to ask, could you please clarify to me why did it work on Osgeld tutorial? (http://www.instructables.com/files/orig/F7J/52X0/G1ZGOSRQ/F7J52X0G1ZGOSRQ.jpg)

Thank you all! LG