Led matrix with arduino

8x8 led matrix control with arduino tutorial

In this tutorial, I wil be explaining how to use a led matrix. To be able to follow this tutorial, you will already have to be familiar with multiplexing. For this project you will need a led matrix which we have an excellent kit for that is available here.

For this project you will be needing two breadboards, an Arduino and some wires. The first thing we are going to do, is hooking everything up. To make everything easier, we will be placing the display in the middle of two breadboards like in the picture. It also might be useful to place it on the very top to make it easier to count where the wires should be.

Now that we have placed the display, we can start plugging in all of the wires. Do everything according to the following schematic, the bottom of the display being the side of the label.

Now that everything is hooked up, we can start coding. The first piece of code is for defining everything. We make a list of pins so we can eventually go through them and light up every LED. Then we define the picture we want to show on the matrix, in this case a smiley. Finally, we define all of the pins as output.

//Pin names for rows
int R[] = {2,7,A5,5,13,A4,12,A2};
//Pin names for columns
int C[] = {6,11,10,3,A3,4,8,9}; 

unsigned char smiley[8][8] = // binary code for smiley
 {  
   0,0,0,0,0,0,0,0,  
   0,0,0,0,0,0,0,0,  
   0,0,1,0,0,1,0,0,  
   0,0,0,0,0,0,0,0,  
   0,1,0,0,0,0,1,0,  
   0,1,0,0,0,0,1,0,  
   0,0,1,1,1,1,0,0,  
   0,0,0,0,0,0,0,0,  
 }; 
void setup()  
 {  
  // Setting all the pins
   for(int i = 0;i<8;i++)  
   {  
     pinMode(R[i],OUTPUT);  
     pinMode(C[i],OUTPUT);  
   }  
 }

The next piece of code will draw out all of the pixels. To do this, we go through all of the pixels and briefly turn them on. Then after drawing everything, we clear the matrix to make room for the second time we draw it.

void loop()  
  {  
   Display(smiley);  //displaying the smiley
 }
  void Display(unsigned char dat[8][8])    
  {  
    for(int c = 0; c<8;c++)  
    {  
      digitalWrite(C[c],LOW);
      for(int r = 0;r<8;r++)  
      {  
        digitalWrite(R[r],dat[r][c]);  
      }  
      delay(1);  
      Clear();
    }  
  }  
  void Clear() //function for clearing the display 
  {  
    for(int i = 0;i<8;i++)  
    {  
      digitalWrite(R[i],LOW);  
      digitalWrite(C[i],HIGH);  
    }  
  } 

If you have done everything correctly, you should now be seeing a lovely smiley.

Leave a Reply

Your email address will not be published. Required fields are marked *

[]