# 9*9 LED Matrix With Arduino

25,886

51

42

## Introduction: 9*9 LED Matrix With Arduino

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.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## 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)

## 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

### Attachments

Participated in the
Arduino Contest

133 9.5K
81 7.3K
195 12K

## 42 Discussions

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...

Heres the code i used:

const int row[8] = { 0,1,2,3,4,5,6,7 }; // positive pin

const int col[10] = { 8,9,10,11,12,14,15,16,17,18}; // negative pin

int n = 100;

int pixels[8][10]; //the matrix

void setup(){

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

//initialize the output pins

pinMode(col[thisPin], OUTPUT);

pinMode(row[thisPin], OUTPUT);

// thake the col pins high to ensure that the LED's are off

digitalWrite(col[thisPin], HIGH);

}

}

void loop(){

int x ;

//We will use the same algorithm as last time but move the image every 100 ms

int Tmatrix[8][32] = {

{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},

{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},

{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},

{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},

{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},

{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},

{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},

{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}

};

x = 1100; //almost 100 ms

int anim = 0; //the counter for the Tmatrix

while(1){

//while (x>0){

//x--;

for(int C = 0; C<8; C++){

for(int L = 0; L<8; L++){

if(Tmatrix[L][C+anim] == 1){

digitalWrite(row[L], HIGH);

digitalWrite(col[C], LOW);

delayMicroseconds(n);

}

digitalWrite(row[L], LOW);

digitalWrite(col[C], HIGH);

delayMicroseconds(n);

}

}

delay(50);

anim++;

if (anim == 32) anim=0;

//}

}

}

Change the values being passed to the delay() or delaymicroseconds() to something bigger

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.

If the scrolling matrix is very long, it will distort the message. Any ideas on how to fix this?

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.

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 "manually"), next step will be to write a program to light up just one led ....

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???

#define R1 0 //digital pin C stands for colums
#define R2 1 //digital pin R stands for rows
#define R3 2 //digital pin
#define R4 3 //digital pin
#define R5 4 //digital pin
#define R6 5 //digital pin
#define R7 6 //digital pin
#define R8 7 //digital pin
#define R9 8 //digital pin
#define C1 9 //digital pin
#define C2 10 //digital pin
#define C3 11 //digital pin
#define C4 12 //digital pin

void setup() {
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(R4, OUTPUT);
pinMode(R5, OUTPUT);
pinMode(R6, OUTPUT);
pinMode(R7, OUTPUT);
pinMode(R8, OUTPUT);
pinMode(R9, OUTPUT);
pinMode(C1, OUTPUT);
pinMode(C2, OUTPUT);
pinMode(C3, OUTPUT);
pinMode(C4, OUTPUT);
}

void loop() {
digitalWrite(R1, LOW); //here all the way till the first delay
digitalWrite(R2, LOW); //i set the anodes and cothodes opposite
digitalWrite(R3, LOW); //so that they are all off
digitalWrite(R4, LOW);
digitalWrite(R5, LOW);
digitalWrite(R6, LOW);
digitalWrite(R7, LOW);
digitalWrite(R8, LOW);
digitalWrite(R9, LOW);
digitalWrite(C1, HIGH);
digitalWrite(C2, HIGH);
digitalWrite(C3, HIGH);
digitalWrite(C4, HIGH);
delay(500);
digitalWrite(R6, HIGH);
digitalWrite(C1, LOW);
delay(1000);
}

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 ;

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.