# Power requirements of a 9x9 LED matrix

Hi,

I have searched first hand for this topic on this forum but have not found satisfactory answer to my problem (or its just I wasnt able to understand, not a very much experienced person in electronics).

I am building a 9x9 LED matrix with rows connected with Anodes and columns connected with cathodes. I am using standard red 5mm LEDs (Voltage drop 2v, Current rating 20mA). I am a bit confused about the power requirements of this arrangement. Most schematics on internet are just connecting rows and columns directly to Arduino pins but I wonder whether Arduino will be able to supply current to a whole row (if in some case we wanna light up all 9 LEDs of 1 row)? Safest assumption will be to assume a case where all 81 LEDs are lit! As far as my knowledge is concerned Arduino can supply 40mA max. per pin and 200mA on whole before frying up.

So should I be using an external power source with Transistors for each row? (1 power supply connected to 9 rows in parallel with 9 transistors in place). If yes, then how should I select the power source voltage?

Secondly, what will be the value of current limiting resistor for each row? (I believe 1 resistor per row will be enough).

As far as my knowledge is concerned Arduino can supply 40mA max. per pin and 200mA on whole before frying up.

That is right.

Most schematics on internet are just connecting rows and columns directly to Arduino pins

Those are crap. There's a lot of it about.

Most likely the matrix will be multiplexed, either by column or row. Therefore only one column or row is on at any one time. So for 20mA current in your LEDs you have just 20 * 9 = 180mA.

It is the common line (column or row) that needs the transistor, and the opposite (column or row) for your current limiting resistor.

I believe 1 resistor per row will be enough

The current should pass through only 1 LED and 1 Resistor. If you have the current of several LEDs going through 1 LED then that is wrong.

http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Thanks for reply Mike. I went through this article you gave. But it raised the following question,

If we are lighting up just one LED at one time during scan, then with the help of a current limiting resistor attached to a row, why is there still a danger of Arduino getting fried up? Doesn't it mean that Arduino will be supplying maximum 20mA (limited by resistor) at any one instant? If yes then it means that the schematics without an external power source are all OK...???

Secondly, I want to display 3 images (through bit patterns stored in bytes) on the matrix, controlled by 3 push buttons. If I press Button 1, pattern 1 should be displayed and remain there until another button is pressed to change the image, if I press Button 2, pattern 2 should be displayed in similar fashion..to achieve this, if i follow the following scheme,

byte image1[] = ..
byte image2[] = ..

setup() { all initialization stuff.. }

loop() {

if button1 == 1 then call displayFunction(image 1)

if button2 == 1 then call displayFunction(image 2)

}

disPlayFunction declaration {

all scanning code goes here

}

This scheme WONT WORK obviously. The problem which I can see is that it will scan all rows n column for 1 time, display the required image for an instant and then exit the function turning off all the LEDs. HOW TO MAKE THE IMAGE STAY there? Secondly, If I do something to keep compiler scanning and scanning and remain inside the displayFunction then I wont be able to read other buttons in the loop function?

Any help on this?

arslanzaidi:
If we are lighting up just one LED at one time during scan,

Because you do not light up just one LED at a time.

To drive your matrix, you want to light up a whole row - or column - at a time so you need to provide the current for all of the LEDs in that row or column. And because this is only for a part of the time, you want to do so with the maximum current available, so limiting the current for each LED to the appropriate fraction permissible when driving multiple pins on the Arduino is generally not an option.

If you are content to have each LED driven at 2 mA for one eighth (or in your case, one ninth) of the time, then it will work. OK?

The problem which I can see is that it will scan all rows n column for 1 time, display the required image for an instant and then exit the function turning off all the LEDs. HOW TO MAKE THE IMAGE STAY there?

You do not turn it off on exit. You leave it on until you enter the routine again to change it.

If I do something to keep compiler scanning and scanning and remain inside the displayFunction then I wont be able to read other buttons in the loop function?

Yes you will. You only change the display when you enter the scan routine, after that your time is your own to read the buttons.

you want to light up a whole row - or column

really? How? I mean I am not able to understand the concept, we give HIGH on row A and give LOW on row 1, it will light up just 1 LED.. how does a whole row light up comes in? (Am I missing some basic electronic stuff? )

You do not turn it off on exit. You leave it on until you enter the routine again to change it.

If I do not turn an LED off at the last statement of the loop (of scan routine), how will the next LED be turned on on the next iteration of the loop? (one LED light up at one time..small delay..then other..small delay..then other LED...so on..)

Just to make sure I and you both are on the same page, let me paste the reference code which I am using and trying to modify. It's from Arduino CookBook.

``````/*
* matrixMpxAnimation sketch
* animates two heart images to show a beating heart
*/
// the heart images are stored as bitmaps - each bit corresponds to an LED
// a 0 indicates the LED is off, 1 is on

byte bigHeart[] = {
B01100110,
B11111111,
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00000000};

byte smallHeart[] = {
B00000000,
B00000000,
B00010100,
B00111110,
B00111110,
B00011100,
B00001000,
B00000000};
const int columnPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
const int rowPins[] = { 10,11,12,15,16,17,18,19};
void setup() {
for (int i = 0; i < 8; i++)
{
pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
pinMode(columnPins[i], OUTPUT);
digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
}
}
void loop() {
int pulseDelay = 800 ; // milliseconds to wait between beats
show(smallHeart, 80); // show the small heart image for 100 ms
show(bigHeart, 160); // followed by the big heart for 200ms
delay(pulseDelay); // show nothing between beats
}
// routine to show a frame of an image stored in the array pointed to by the
// image parameter.
// the frame is repeated for the given duration in milliseconds
void show( byte * image, unsigned long duration)
{
unsigned long start = millis(); // begin timing the animation
while (start + duration > millis()) // loop until the duration period
has passed
{
for(int row = 0; row < 8; row++)
{
digitalWrite(rowPins[row], HIGH); // connect row to +5 volts
for(int column = 0; column < 8; column++)
{
if(pixel == 1)
{
digitalWrite(columnPins[column], LOW); // connect column to Gnd
}
delayMicroseconds(300); // a small delay for each LED
digitalWrite(columnPins[column], HIGH); // disconnect column from Gnd
}

digitalWrite(rowPins[row], LOW); // disconnect LEDs
}
}
}
``````

I mean I am not able to understand the concept, we give HIGH on row A and give LOW on row 1, it will light up just 1 LED.. how does a whole row light up comes in? (Am I missing some basic electronic stuff? )

Go back to that page I linked :-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html
I think you missed something. The walking one concept shows that you either light up one row or one column at a time.
If you only light up one LED at a time then you have to have 64 individual lighting to get a full 8 by 8 matrix. That means any one LED is only on one sixty-fourth of the time. This means it will be very dim. If you light up a whole row at a time then each LED will be on one eights of the time and will be much brighter. However this is still dimmer than having an LED on all the time but that is the price you pay for multiplexing.

If I do not turn an LED off at the last statement of the loop (of scan routine), how will the next LED be turned on on the next iteration of the loop?

? ? ? - it is turned on with code. You enter the scan refresh routine, the first thing you do is turn the lit LED row off. Then you turn the next LED row on, then you leave the the scan refresh routine. That is how it works, that is how you should do it.

Just to make sure I and you both are on the same page, let me paste the reference code which I am using and trying to modify. It's from Arduino CookBook.

It is just that, reference code, it does what it does but you would never do that in a real application. It contains code like:-

``````while (start + duration > millis()) // loop until the duration period has passed
``````

Which is just a blocking delay. You must write the code like I showed in that page, a quick routine that changes the row ( or column ) currently being displayed for the next one and then returns. This refresh routine must be called regularly preferably with a timer interrupt but you can do it with the "blink without delay technique" to start off.

Ok thanks everyone for valuable inputs. But i have figured out the answer to my question. There can b 2 techniques of scanning.

The calculation of limiting resistor also depends on the algorithm being used to display anything on the matrix. The algorithm which I was using (as i have quoted above too) lights up ONLY & ONLY 1 LED at a time (for some microseconds), then turns it off and turns on the next one. so in this case I need to calculate the resistance according to just 1 led. in my case, using 5V supply from Arduino Pins, 2V drop across LED, 20mA current rating, R comes out to be exactly 150 ohms.

The disadvantage might be somewhat dimmer LEDs as compared to the other method, but it is compensated by the fact that we can provide 20mA of current to the LED instead of X ( X= 40mA / No. of LEDs per row ).

The other method off course comprises lighting up all LEDs in a single row or column at a time, delay of some microseconds, then turning them all off and moving to the next row/column. So we have to limit the current to X as Arduino cannot provide greater than 40mA per pin. I believe in case of a 8x8 or 9x9 matrix, I will have even dimmer LEDs using this technique as compared to the 1st one.

Similarly, there can be a case where multiple rows/columns can also be turned on at same time. (depends on the type of image you want to display.) In that case one has to consider not only 40mA per pin constraint but also the 200mA constraint for all pins considered collectively.

The 1st algo is the best one for my needs. As it can display ANY image with good brightness levels.

Experts can rectify if there is anything wrong in my theory.

20 mA through the LED for one 81st of the time does not amount to much.

If you use transistors to buffer either columns or rows, you can light up all of the LEDs in a column or row together as needs be, and do this for a given column or row for one ninth of the time, increasing your brightness by nine times.

If you also use "Charlieplexing", you can drive the whole array with only 10 pins. (Note that the final circuit in that article erroneously illustrates resistors in the base lines to the transistors - they should not be there but that detail is only mentioned toward the end of the discussion.)

Experts can rectify if there is anything wrong in my theory.

OK - you are wrong.

The 1st algo is the best one for my needs. As it can display ANY image with good brightness levels.

Any method of multiplexing can display any image and that method is particularly poor about LED brightness.

The disadvantage might be somewhat dimmer LEDs as compared to the other method, but it is compensated by the fact that we can provide 20mA of current to the LED instead of X ( X= 40mA / No. of LEDs per row ).

That is only if you are driving both ends of the LEDs directly from an arduino pin and you would be mad to do that.

That is only if you are driving both ends of the LEDs directly from an arduino pin and you would be mad to do that.

I didnt get that Grumpy what do you mean?

ok i accept i am wrong..but how? why? where? please elaborate.

this discussion is really going interesting!

Both ends of the LED means that the anode is held high with an arduino output pin and the cathode is held low with an arduino pin. It is normal for one end to be driven with something that can provide enough current for 8 LEDs to be on any one time. This normally means a top driver in the case of anodes, like a PNP transistor, or a current sink in the case of the cathodes.
You have this driver on the "walking" side of the matrix.