Introduction: 9*9 LED Matrix With Arduino

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

Step 1: Basics

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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





Comments

AndyM6 (author)2015-05-02

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;

//}

}

}

KevinW55 (author)AndyM62016-01-14

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

loko42 (author)2014-10-10

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.

Flap jack (author)2014-01-14

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

Diljot (author)2013-05-05

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.

CairParavel314 (author)2011-12-23

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.

zmolroc (author)CairParavel3142011-12-23

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.

axeman911 (author)2011-06-22

there still seems to be something wrong with your program about the while statement?

zmolroc (author)axeman9112011-06-22

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

axeman911 (author)zmolroc2011-06-23

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.

zmolroc (author)axeman9112011-06-23

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

axeman911 (author)zmolroc2011-06-23

thanx, i will try that

axeman911 (author)axeman9112011-06-23

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

zmolroc (author)axeman9112011-06-24

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

axeman911 (author)2011-06-16

there is something wrong with ur program a copyied it and ran it but there is some problem with the while(1){} command?

zmolroc (author)axeman9112011-06-16

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.

axeman911 (author)zmolroc2011-06-17

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?

zmolroc (author)axeman9112011-06-19

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 ;

axeman911 (author)2011-05-24

if the input voltage is 5v don't you need a resistor for the leds?

zmolroc (author)axeman9112011-05-25

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.

axeman911 (author)zmolroc2011-05-25

srry but if u plug in the usb cable it is 5v.
but would it still work if i put a resistor

zmolroc (author)axeman9112011-05-25

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.

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.

axeman911 (author)zmolroc2011-05-25

thanx but what if i want to turn on an entire colum or row on at a time to spell words?

so ur saying that the voltage that comes out of the pins is less then 5V?

zmolroc (author)axeman9112011-05-25

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.

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.

axeman911 (author)zmolroc2011-05-25

srry last one i swear so if i am using the 5v ones i need a resistor

zmolroc (author)axeman9112011-05-25

ok, i think a 470 Ohm resistor it's enough

axeman911 (author)zmolroc2011-05-25

thank you soooo much!!! :)

zmolroc (author)axeman9112011-05-26

no problem .....

axeman911 (author)zmolroc2011-05-25

and what if i leave the leds on for longer.

axeman911 (author)2011-05-25

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

zmolroc (author)axeman9112011-05-25

Yes, i've done exactly this in the demo.

crusy (author)2011-05-08

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?

zmolroc (author)crusy2011-05-08

the brightness of the LED suffers, but Arduino it's ok. If you want the LED full power you need to integrate some transistor.

pbriz (author)2010-10-13

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?

By the way, thanks for this post, its been very helpful!

Mario1 (author)2010-10-07

Whats up with most of your LEDs not lighting?
Is this caused by an LED itself or you messed up the soldering?

zmolroc (author)Mario12010-10-08

The LED itsefl, i found too late.

GOwin (author)2010-01-09

CAn you use the original Arduino serial for this? Can the ATMega8 handle this?

zmolroc (author)GOwin2010-01-10

 i think he can handle. i haven't worked with atmega8 but i think he can do the job

winkman (author)2009-11-21

 I did this for a project a while ago, because  saw a description etc on the Arduino website. Worked well :)

zmolroc (author)winkman2009-11-22

 Thanks :D

just_watching (author)2009-11-18

you could also use the arduino mega or a clone of it then u can drive even more leds

zmolroc (author)just_watching2009-11-18

 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  for buttons or something else ....

About This Instructable

20,969views

49favorites

License:

More by zmolroc:9*9 LED matrix with Arduino
Add instructable to: