• Pooja Velavan

Interfacing the Arduino with an 8*8 LED Matrix

#LED lights are often used to display the output of any circuits. They are also packed into rows and columns of the matrix with a number of LED's has pixel to display the specific signs, symbols, or messages. These matrix arrangements are available in a combination of a single color or multi-color LEDs.


In this article, let us learn how to interface 8*8 LED matrix display with the #Arduino board and the coding to display the desired character in it. Let's quickly start with the requirements to build the project.


Hardware Requirements:


1. Breadboard


Breadboard
Breadboard

A breadboard is an essential component that is in a rectangular shape with small holes in it that are used to insert the components to test the circuits. The connections are not fixed and can be varied. In a breadboard, the holes in one horizontal line are in series connection with each other. Breadboards are made from plastic or wood and come in all shapes, sizes, and even different colors, the most commonly used sizes for designing the circuits are "full-size," "half-size," and "mini" breadboards.


Buy the Breadboard from here.


2. Arduino UNO


Arduino UNO
Arduino UNO

#Arduino board is a microcontroller that is used to accept inputs from sensors connected and provide an output action on the desired device connected to it. The sensor inputs can be from light-detecting sensors, motion sensors (Ultrasonic or IR), temperature sensors, etc. The output from this device can be received through other output devices such as LED, Buzzer, Serial monitor, etc.


Buy Arduino UNO from here.


3. 8*8 LED Matrix


8*8 LED Matrix
8*8 LED Matrix

8*8 LED #matrix consists of 64 pixels in which each pixel has a LED connected to it. The LED's are arranged in rows and columns in a matrix and are connected to the 16 pinouts.


Buy 8*8 LED Matrix from here.


4. Jumper Wires


Jumper Wires
Jumper Wires

These are the main components that are used to establish the connections between different devices of the circuit.


Buy Jumper Wires from here.


5. USB Cable


USB Cable
USB Cable

This cable is used to connect the Arduino board to the power supply. It also helps in the transmission of data.


Buy USB Cable from here.


Software Requirements:

1. Arduino IDE


Arduino IDE
Arduino IDE

Arduino #IDE (Integrated Development Platform) which is used to interface the Development boards like NodeMCU to run the desired code designed to #interface hardware devices.


Circuit Connections:


Circuit Connection
Circuit Connection

The Circuit connection between the #LED Matrix and Arduino involves the following steps.

  • First, we have to determine which is the Row pins and Column pins out of the 16 pins. There are 8 rows and 8 columns in the matrix.

  • On determining the rows and columns, connect the pins accordingly to the Arduino board.

  • Based on the LED positioning the connection can be done by connecting the row pin to the supply voltage of the Arduino board and the column pin to the ground.

  • Hence, there are 16 pins in the matrix the connection is a little bit complicated. Let us see which pin is to be connected to which row and column:

ROW_1 to DIGITAL PIN 2

ROW_2 to DIGITAL PIN 3

ROW_3 to DIGITAL PIN 4

ROW_4 to DIGITAL PIN 5

ROW_5 to DIGITAL PIN 6

ROW_6 to DIGITAL PIN 7

ROW_7 to DIGITAL PIN 8

ROW_8 to DIGITAL PIN 9

COLUMN_1 to DIGITAL PIN 10

COLUMN_2 to DIGITAL PIN 11

COLUMN_3 to DIGITAL PIN 12

COLUMN_4 to DIGITAL PIN 13

COLUMN_5 to ANALOG PIN A0

COLUMN_6 to ANALOG PIN A1

COLUMN_7 to ANALOG PIN A2

COLUMN_8 to ANALOG PIN A3


Code Explanation:


Let us learn how to glow a single LED out of the LED matrix. In this code, let us make the LED in row_2 and column_6 to switch ON. Let us understand the following code:

int R2=3; 

Initialize the integer value as the row_2 of the LED matrix is connected to the PIN 3 of the Arduino board.

#define C6 A1

Using the defined set the column_6 of the LED matrix is connected to the Analog PIN 1 of the Arduino board.

void setup() {
// put your setup code here, to run once:
pinMode(R2,OUTPUT);
pinMode(C6,OUTPUT);
digitalWrite(R2,HIGH);
digitalWrite(C6,HIGH);
}

In the setup ( ) function, the inbuilt function pinMode( ) is used to declare the R2 and C6 as output pins. Initially, both the pins are set to "HIGH".

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(C6,LOW);
delay(1000);
digitalWrite(C6,HIGH);
delay(1000);
}

In the loop( ) function, When both the pins are set to "HIGH" there will be no output. Hence the Column_6 pin is set to "LOW" which makes the LED to glow with 1 milliseconds delay and changed to "HIGH" which turns OFF the LED with 1 milliseconds delay. This loop function is repeated, which turns ON and OFF the respective LED.


Complete Code:

To switch ON one particular LED in the Matrix.

int R2=3; 
#define C6 A1
void setup() {
// put your setup code here, to run once:
pinMode(R2,OUTPUT);
pinMode(C6,OUTPUT);
digitalWrite(R2,HIGH);
digitalWrite(C6,HIGH);
}
void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(C6,LOW);
delay(1000);
digitalWrite(C6,HIGH);
delay(1000);
}
first_code
.txt
TXT • 322B

Note: Please change the file extension to .ino(Arduino IDE) file format before you upload the code to the Arduino board.


Now, let us learn how to display a specific pattern or characters using this LED Display. We will learn the code to display the Letter "B" in the LED Matrix.


#define ROW_1 2  
#define ROW_2 3  
#define ROW_3 4   
#define ROW_4 5  
#define ROW_5 6  
#define ROW_6 7  
#define ROW_7 8   
#define ROW_8 9   

#define COL_1 10  
#define COL_2 11   
#define COL_3 12   
#define COL_4 13  
#define COL_5 A0   
#define COL_6 A1   
#define COL_7 A2  
#define COL_8 A3 

Initialize the rows and columns to which the Arduino #Analog/Digital pins are connected.

const byte rows[] = {
    ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8
};

Array for rows is created to store the byte values from row 1 to row 8.

byte A[] = {B00011000,B00111100,B01100110,B01100110,B01111110,B01111110,B01100110,B01100110};

The above statement is the array of byte values declared to display the letter "A".The byte values are determined based on selecting the LEDs in the rows and columns of the matrix to glow to form the "A" alphabet. And "B" in the array indicates that they are byte values.


byte B[] = {B01111100,B01100110,B01100110,B01111100,B01111110,B01100110,B01100110,B01111100};

Similarly, the above statement is the array of byte values declared to display the letter "B".

void setColumns(byte b) {
    digitalWrite(COL_1, (~b >> 7) & 1); // Get the 1st bit: 10000000
    digitalWrite(COL_2, (~b >> 6) & 1); // Get the 2nd bit: 01000000
    digitalWrite(COL_3, (~b >> 5) & 1); // Get the 3rd bit: 00100000
    digitalWrite(COL_4, (~b >> 4) & 1); // Get the 4th bit: 00010000
    digitalWrite(COL_5, (~b >> 3) & 1); // Get the 5th bit: 00001000
    digitalWrite(COL_6, (~b >> 2) & 1); // Get the 6th bit: 00000100
    digitalWrite(COL_7, (~b >> 1) & 1); // Get the 7th bit: 00000010
    digitalWrite(COL_8, (~b >> 0) & 1); // Get the 8th bit: 00000001
}

A new function is created in the name of "setColumns" for the letter "B". In this, each row byte value of the "B" alphabet is separated into columns as shown above. Then in the columns, the bit operation is performed to show the rows and columns byte values are opposite to make the LEDs glow.

void  drawScreen(byte buffer2[]){
    for (byte i = 0; i < 8; i++) {
    setColumns(buffer2[i]); // Set columns for this specific row
          
    digitalWrite(rows[i], HIGH);
    delay(100); // Set this to 50 or 100 if you want to see the multiplexing effect!
    digitalWrite(rows[i], LOW);
        
    }
}

Create another function "drawScreen" and enter the byte array into the function. Perform for loop, by declaring the "i" initially has 0 and "i" less than 8 that is the number of rows then incremented it. Then based on the ith value of the row is set to "HIGH" and with the delay of 100 milliseconds, it is changed to "LOW" again.

void setup() {
  // put your setup code here, to run once:
   for (byte i = 2; i <= 13; i++)
  pinMode(i, OUTPUT);
 
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);

}

In the setup ( ) function, the inbuilt function pinMode( ) is used to declare the OUTPUT pins.

void loop() {
  // put your main code here, to run repeatedly:
  drawScreen(B);

}

In the loop( ) function, the drawScreen function to display the "B" alphabet is declared and it runs repeatedly. Thus, ends the loop function.


Complete Code:


The code to display the "B" alphabet in the LED matrix is shown below:

#define ROW_1 2  
#define ROW_2 3  
#define ROW_3 4   
#define ROW_4 5  
#define ROW_5 6  
#define ROW_6 7  
#define ROW_7 8   
#define ROW_8 9   

#define COL_1 10  
#define COL_2 11   
#define COL_3 12   
#define COL_4 13  
#define COL_5 A0   
#define COL_6 A1   
#define COL_7 A2  
#define COL_8 A3 

const byte rows[] = {
    ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8
};

byte A[] = {B00011000,B00111100,B01100110,B01100110,B01111110,B01111110,B01100110,B01100110};
byte B[] = {B01111100,B01100110,B01100110,B01111100,B01111110,B01100110,B01100110,B01111100};


void setColumns(byte b) {
    digitalWrite(COL_1, (~b >> 7) & 1); // Get the 1st bit: 10000000
    digitalWrite(COL_2, (~b >> 6) & 1); // Get the 2nd bit: 01000000
    digitalWrite(COL_3, (~b >> 5) & 1); // Get the 3rd bit: 00100000
    digitalWrite(COL_4, (~b >> 4) & 1); // Get the 4th bit: 00010000
    digitalWrite(COL_5, (~b >> 3) & 1); // Get the 5th bit: 00001000
    digitalWrite(COL_6, (~b >> 2) & 1); // Get the 6th bit: 00000100
    digitalWrite(COL_7, (~b >> 1) & 1); // Get the 7th bit: 00000010
    digitalWrite(COL_8, (~b >> 0) & 1); // Get the 8th bit: 00000001
}

void  drawScreen(byte buffer2[]){
    for (byte i = 0; i < 8; i++) {
    setColumns(buffer2[i]); // Set columns for this specific row
          
    digitalWrite(rows[i], HIGH);
    delay(100); // Set this to 50 or 100 if you want to see the multiplexing effect!
    digitalWrite(rows[i], LOW);
        
    }
}


void setup() {
  // put your setup code here, to run once:
   for (byte i = 2; i <= 13; i++)
  pinMode(i, OUTPUT);
 
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  drawScreen(B);

}

ADVANCED_code
.txt
TXT • 2KB

Note: Please change the file extension to .ino(Arduino IDE) file format before you upload the code to the Arduino board.


Working:

The working procedure is very simple. On connecting the circuit, upload the program to the Arduino board by using the #USB cable. The below image shows the picture of the circuit when the code is not applied.

When Code is not uploaded
When Code is not uploaded

On uploading the code to the Arduino to display the alphabet "B", wait for some time to upload the program and the output display is shown below.


On uploading the Code
On uploading the Code

Video explanation is provided with the practical implementation, for a more beneficial perception.


Video By - Aishwarya Balajee

The LED matrix finds its application in Traffic Lights, Text signs, or emojis, Signboards, etc. Take the first step to design the circuit by keeping this article as a basic tutorial and try to develop the circuit on your own. Try yourself by creating patterns or symbols in the LED matrix by making the respective LEDs to glow and create or modify the coding part according to your desired output.


See also:

  1. How to control an LED using Push button and Arduino?

  2. Interfacing Temperature Sensor with Arduino

  3. Interfacing DC Motor with Arduino