# 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 = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; // the anodes
const int col  = {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 = {
{ 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

Participated in the
Arduino Contest

## 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 = { 0,1,2,3,4,5,6,7 }; // positive pin

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

int n = 100;

int pixels; //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 = {

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

//}

}

}

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);
}