How to program led matrix with Arduino

Hi guys, in today’s tutorial , we will be working with the popular 8×8 LED Matrix m7219 and an Arduino Uno  and display simple text or characters on the LED Matrix. The procedure is very simple and it is an ideal project for beginners.




The 8×8 LED matrix displays are typically used for displaying Short text but They can be joined  to form large displays which can be used for the display of scrolling texts, logos among others etc. In this tutorial, we will be using a single 8×8 LED matrix which is based on the MAX7219 LED driver module. The driver module creates an interface which makes it easy to communicate with the LED matrix. The LED matrix being used in this tutorial comes pre-soldered with the MAX7219 Controller module and can be bought for around 200-299Rs Inr. 

Components Required :

Arduino uno

Led matrix module

Jumper wires

Circuit diagram :



As you can see in diagram the pin connections are very simple which are as described below

LedMatrix ➡️ Arduino

Vcc➡️ 5v

GND➡️ GND

DIN➡️ D 12

CS➡️ D 11

CLk➡️ D10

CODE :
 To run the code for led matrix first you have to download and install led matrix library from link given below 

https://github.com/wayoda/LedControl

Once the Library is installed,  we are ready to  write the code.
the first thing we do is include the library that will be used as shown below



#include <LedControl.h>
after that declare the pins of the Arduino to which each pin of the LED matrix is connected.
int DIN = 12;
int CS =  11;
int CLK = 10;

Now we declare the byte arrays which represent characters or graphics which we want to display.
You can easily creat byte arrays using the software link given below on android 

Ledmatrix  Font Generator

After that create some byte arrays and add them to this.


  //INFO 24*7
    byte b1[8]= {0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E};
    byte b2[8]= {0x00, 0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0x00};
    byte b3[8]= {0x7C, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40};
    byte b4[8]= {0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00};
    byte b5[8]={0xE9, 0x29, 0xEF, 0x81, 0xE1, 0x00, 0x00, 0x00};
    byte b6[8]={0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00};
    byte b7[8]={0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00};


Next, initialize the LED control library by creating an object of the library after which we move to the void setup function to prepare the display by taking it off the power saving mode, setting the brightness of the LEDs to maximum and clearing the Display

LedControl lc=LedControl(DIN,CLK,CS,0);
void setup(){
 lc.shutdown(0,false);       //The MAX72XX is in power-saving mode on startup
 lc.setIntensity(0,15);      // Set the brightness to maximum value
 lc.clearDisplay(0);         // and clear the display
}

Now, we move to the loop function. since our goal is to display the graphics, its the only thing that really needs to be done there. The printbyte() function is used to display the character or graphics stored in any of the byte arrays .



void loop(){
      //INFO 24*7
    byte b1[8]= {0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E};
    byte b2[8]= {0x00, 0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0x00};
    byte b3[8]= {0x7C, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40};
    byte b4[8]= {0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00};
    byte b5[8]={0xE9, 0x29, 0xEF, 0x81, 0xE1, 0x00, 0x00, 0x00};
    byte b6[8]={0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00};
    byte b7 [8]={ 0x3E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00};
   
   
//INFO 24*7
    printByte(b1);
    delay(1000);
    printByte(b2);
    delay(1000);
    printByte(b3);
    delay(1000);
    printByte(b4);
    delay(1000);
    printByte(b5);
    delay(1000);
    printByte(b6);
    delay(1000);
    printByte(b7);
    delay(1000);

}
void printByte(byte character [])
{
    int i = 0;
  for(i=0;i<8;i++)
  {
    lc.setRow(0,i,character[i]);
  }
    }


You can download the full code from link given below 




That’s all for this tutorial, thanks for  reading. You can show support by dropping comments here and subscribing to our channel on youtube.


No comments:

Powered by Blogger.