Ever wanted to have a bigger display?

This display is based on an 9*9 green LED Matrix. The display is driven just with one Arduino board (Duemilanove in my case).

Why do we use a matrix and we don't light's up the leds individually?

Basic :
A led have 2 pin's: anode & cathode.
So even we put the led's with the common cathode, we will still have 81+1 pin's, the arduino board isn't enought for this.

In a matrix we can put the columns to the cathode and the rows to the anode of the Led's, so here we will have just 9+9 pin's, better then the other but a little tricky on the programming stuff.

## Step 1: Basics

What do you need :

- 81 green LED's (or other color)
- an test PCB
- and an arduino board

next we need the schematics :

Matrix hardware

I have build the matrix like next :
- the columns have the cathode's of the LED's
- the rows have the anode of the LED's

Arduino Pin's :

Now we will have to connect the matrix to the arduino board :

the rows :

- the row 1 to digital pin 0
- the row 2 to digital pin 1
- the row 3 to digital pin 2
- the row 4 to digital pin 3
- the row 5 to digital pin 4
- the row 6 to digital pin 5
- the row 7 to digital pin 6
- the row 8 to digital pin 7
- the row 9 to digital pin 8

the columns :
- the column 1 to digital pin 9
- the column 2 to digital pin 10
- the column 3 to digital pin 11
- the column 4 to digital pin 12
- the column 5 to analog input pin 0 (there is no problem we can use it like a digital one, i'll show you later)
- the column 6 to analog input 1
- the column 7 to analog input 2
- the column 8 to analog input 3
- the column 9 to analog input 4

## Step 2: The Analog Pin's

We have connected the columns 5, 6, 7, 8 & 9 to the analog input's 0, 1, 2, 3, 4 on the Arduino board.

On the columns we have the cathode's from the led's so we need an input here, but if we will have an input the port we will be always open so the column we will be always on when we will output the rows.

To avoid this we will make the analog input pin's to be used like outputs.

To do this we use the command :

"pinMode(col[thisPin], OUTPUT);"

What's with all the stuff there, in next section.

## Step 3: Programming Setup

First we need to define the pin's.
and you need to know that in digital mode the analog input pin's are defines like : 14,15,16,17,18,19.

we have row's and column's so :

const int row[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; // the anodes
const int col[9]  = {9, 10, 11, 12, 14, 15, 16, 17, 18}; // the cathodes

next we need to setup the matrix

void setup(){
for (int thisPin = 0; thisPin < 9; thisPin++){

//we initialize the pins as output's
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);

// now we have to make the columns high so that all the LED's will be off
digitalWrite(col[thisPin], HIGH);
}
}
void loop(){
}
this is the setup stuff
next we play

## Step 4: Programming : Light Up the Diagonal

In the last section we made the setup.
Now let's light up the diagonal

First you need to know that if you what to light up just the diagonal you need to turn one the first row ... turn it off then turn on the second row .... turn it of and so on, you must do this fast so the eye don't observe.
This principle is used on the tv's

now in loop()

we have to do something like this :

for ( intPin = 0; Pin < 9; Pin++){
digitalWrite( row[Pin], HIGH); // the anode is high
digitalWrite( col[Pin], LOW);   // the cathode is low

// this turn the led on now we have to let the led on for some time .... 1 microsecond is enough
delayMicroseconds(1);

//now we have tu turn it off so we will inverse the polarity
digitalWrite( row[Pin], LOW);  // the anode is low
digitalWrite( col[Pin], HIGH);  // the cathode is high

//we have turn the led off, next delay it 1 microsecond and  go to the next row
delayMicroseconds(1);

}

We have finish, now we have the diagonal of the matrix on

Let's do something more complex :

## Step 5: Programming : Complex Stuff

If we want to build something more complex and use the last method is a little hard.

But we can do something like this :

int the loop() function :

// first we have to build the matrix in arduino with the shape that we want

int matrix[9][9] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 1, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 1, 1, 1, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 1, 0, 0 }
}
// i have draw an A there, you can draw anithing
// next we have to light up the led's like in the matrix
// first we will make a while that repeats to the infinite, to have the letter on all the time

while(1){
for ( int L = 0; L < 0; L++){ // the "for" for lines
for ( int C = 0; C < 9; C++){ // the "for" for columns

//we verify in the matrix if we have 1 - the led is on
if ( matrix[L][C] == 1){

// if we have 1 in the matrix we light up the corresponding led on the matrix
digitalWrite ( row[L], HIGH);
digitalWrite ( col[C], LOW);
delayMicroseconds(100);
}

// here we turn the led's off
digitalWrite ( row[L], LOW);
digitalWrite ( col[C], HIGH);
delayMicroseconds(100);
}
}
}

so that was it
next some movies and a file with scrolling text.

## Step 6: Videos

Movie's

<p>Hey! i tried to make this except with a 8*10 matrix... i modified the code a bit, but when i upload it, the words scroll very, very, very, very quickly and it is unreadable...</p><p>Heres the code i used:</p><p>const int row[8] = { 0,1,2,3,4,5,6,7 }; // positive pin</p><p>const int col[10] = { 8,9,10,11,12,14,15,16,17,18}; // negative pin</p><p>int n = 100;</p><p>int pixels[8][10]; //the matrix</p><p>void setup(){</p><p> for (int thisPin = 0; thisPin &lt; 9; thisPin++){</p><p> //initialize the output pins</p><p> pinMode(col[thisPin], OUTPUT);</p><p> pinMode(row[thisPin], OUTPUT);</p><p> // thake the col pins high to ensure that the LED's are off</p><p> digitalWrite(col[thisPin], HIGH);</p><p> }</p><p> }</p><p>void loop(){</p><p> int x ; </p><p>//We will use the same algorithm as last time but move the image every 100 ms</p><p> int Tmatrix[8][32] = {</p><p> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},</p><p> {0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0},</p><p> {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0},</p><p> {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},</p><p> {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},</p><p> {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0},</p><p> {0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0},</p><p> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}</p><p> };</p><p> x = 1100; //almost 100 ms </p><p> int anim = 0; //the counter for the Tmatrix</p><p> while(1){</p><p> //while (x&gt;0){</p><p> //x--;</p><p> for(int C = 0; C&lt;8; C++){</p><p> for(int L = 0; L&lt;8; L++){</p><p> if(Tmatrix[L][C+anim] == 1){</p><p> digitalWrite(row[L], HIGH);</p><p> digitalWrite(col[C], LOW);</p><p> delayMicroseconds(n);</p><p> }</p><p> digitalWrite(row[L], LOW);</p><p> digitalWrite(col[C], HIGH);</p><p> delayMicroseconds(n);</p><p> }</p><p> }</p><p> delay(50);</p><p> anim++;</p><p> if (anim == 32) anim=0;</p><p> //}</p><p> }</p><p>}</p>
<p>Change the values being passed to the delay() or delaymicroseconds() to something bigger</p>
<p>Hi, I did similar matrix with shift registers 595, but when start multiplex, display drastically decrease lightning. What could be a problem? When i descrease a speed of multiplexing to only blinking it gives good light. I tried to set up peak current for about 300mA but not better result still.</p>
<p>If the scrolling matrix is very long, it will distort the message. Any ideas on how to fix this?</p>
is it necessary to use resistors and transistors to make the matrix work? cause when i type n the code, the entire row lights up, can't get a single led to light up.
Can you show me a more detailed example of how soldering the LED in the board? I want to do the matrix, but I can't see much from the image and I'm starting with the Arduino also.
Them are solder like in the image with schematics. On the test board you have lines with anodes and in the air lines with cathode or reverse (this is my version)...... You can use whatever you want, as long as you respect the schematic.
there still seems to be something wrong with your program about the while statement?
There is nothing wrong with the loop, the problem is in another place, after defining the matrix you must close that with }; , i typed wrong.... but c'moon this is basic programming ......
yeah i figured that out, now when i upload it, it doesnt light up anything, even though the rows and columns are all in the proper pins.<br>
check if you connected the led's ok, i mean the anode and the cathode are were they are suppose to be. if this is ok, please check if the led's are functional (they are not burned or something, light one up &quot;manually&quot;), next step will be to write a program to light up just one led ....
thanx, i will try that
so here is my program that turns on one led it works, so what is the next step, but when i define the columns 5, 6, 7, 8, and 9 and put them as ouputs to the analog pin, then nothing blinks???<br><br>#define R1 0 //digital pin C stands for colums<br>#define R2 1 //digital pin R stands for rows<br>#define R3 2 //digital pin<br>#define R4 3 //digital pin<br>#define R5 4 //digital pin<br>#define R6 5 //digital pin<br>#define R7 6 //digital pin<br>#define R8 7 //digital pin<br>#define R9 8 //digital pin<br>#define C1 9 //digital pin<br>#define C2 10 //digital pin<br>#define C3 11 //digital pin<br>#define C4 12 //digital pin<br><br>void setup() {<br> pinMode(R1, OUTPUT);<br> pinMode(R2, OUTPUT);<br> pinMode(R3, OUTPUT);<br> pinMode(R4, OUTPUT);<br> pinMode(R5, OUTPUT);<br> pinMode(R6, OUTPUT);<br> pinMode(R7, OUTPUT);<br> pinMode(R8, OUTPUT);<br> pinMode(R9, OUTPUT);<br> pinMode(C1, OUTPUT);<br> pinMode(C2, OUTPUT);<br> pinMode(C3, OUTPUT);<br> pinMode(C4, OUTPUT);<br>}<br><br>void loop() {<br> digitalWrite(R1, LOW); //here all the way till the first delay<br> digitalWrite(R2, LOW); //i set the anodes and cothodes opposite<br> digitalWrite(R3, LOW); //so that they are all off<br> digitalWrite(R4, LOW);<br> digitalWrite(R5, LOW);<br> digitalWrite(R6, LOW);<br> digitalWrite(R7, LOW);<br> digitalWrite(R8, LOW);<br> digitalWrite(R9, LOW);<br> digitalWrite(C1, HIGH);<br> digitalWrite(C2, HIGH);<br> digitalWrite(C3, HIGH);<br> digitalWrite(C4, HIGH);<br> delay(500);<br> digitalWrite(R6, HIGH);<br> digitalWrite(C1, LOW);<br> delay(1000);<br>}<br>
ok, first, nothing blinks because you have them all the time on, they blink but too fast for us, you have to turn them on, then of then on, with a specific delay
there is something wrong with ur program a copyied it and ran it but there is some problem with the while(1){} command?
What problem ?, as you can see, in the video it works is the same program, of course maybe when i've typed here, appeared a space or something and a copy paste will damage the arduino format.
well every time i try to compile or upload it it says that before the while(1) { command a , or ; is expected but i can't find where?
Sorry, for the delayed response, check all the program if there are all the } closed in a correct order, and check if all the lines for ;
if the input voltage is 5v don't you need a resistor for the leds?
Yeah, but you keep the led on for a fraction of a second so, first, second : arduino doesn't have 5v, it's around 2.5v, i don't know why, i measured it.
srry but if u plug in the usb cable it is 5v.<br>but would it still work if i put a resistor
you don'y let the led on longer time, because you have a matrix, and you shift the lines very fast to obtain the object, at a specific time you don't have 2 lines or 2 columns fully on.<br><br>So what the usb has 5v, the internal resistance of the controller reduces the voltage, measure it, the only I/O that has 5v is I/O 13, tested. If you put a resistor of course will work, the resistor limits the current delivered to the led.
thanx but what if i want to turn on an entire colum or row on at a time to spell words?<br><br>so ur saying that the voltage that comes out of the pins is less then 5V?
doesn't matter you cannot keep the line or column ON, more than a fraction of a time, play with it and you will see why.<br><br>Yes, i've seen this to the newest boards, the older ones have 5v, but the newest around 2.5v, exception at I/O 13.
srry last one i swear so if i am using the 5v ones i need a resistor
ok, i think a 470 Ohm resistor it's enough
thank you soooo much!!! :)
no problem .....
and what if i leave the leds on for longer.
like other matrixes in this one is it possible to make the leds light so that you can make words actually fly across the screen and the same for letters
Yes, i've done exactly this in the demo.
from what I read the Arduino can provide 40 mA per pin (http://arduino.cc/en/Main/ArduinoBoardUnoSMD) - isn't this a problem when you turn on all 9 (or even 10) LEDs?
the brightness of the LED suffers, but Arduino it's ok. If you want the LED full power you need to integrate some transistor.
I'm pretty new to this (physical computing) but i'm trying out this project. So far its all good, and makes perfect sense but i noticed that other charlieplexed LED matrixes that I've seen out there tend to include resistors between the LEDs and the power sources (the output pins). Is there a reason why this project doesn't include resistors? Are they used as some sort of precaution normally?<br><br>By the way, thanks for this post, its been very helpful!
Whats up with most of your LEDs not lighting?<br>Is this caused by an LED itself or you messed up the soldering?<br>
The LED itsefl, i found too late.
CAn you use the original Arduino serial for this? Can the ATMega8 handle this?
&nbsp;i think he can handle. i haven't worked with atmega8 but i think he can do the job
&nbsp;I did this for a project a while ago, because &nbsp;saw a description etc on the Arduino website. Worked well :)
&nbsp;Thanks :D
you could also use the arduino mega or a clone of it then u can drive even more leds<br />
&nbsp;yes you are right, you could do that, but i wanted to do it with a regular arduino, and you can drive up to 10*10 but i've let 2 pin's free &nbsp;for buttons or something else ....