How to make an 8×8 LED matrix display using an Arduino Nano

How to make an 8x8 LED matrix display using an Arduino Nano

Hello and welcome back! In this project, we will learn how to make an 8×8 LED matrix display using Arduino Nano. For that, I have used two 74HC594 shift registers, allowing us to control the display using just three pins (not counting the power pins). You can display any character on it, and I used 64 SMD LEDs for this project, which provide bright and clear visuals.

What is an LED matrix display?

An LED matrix consists of rows and columns. In this display, there are 8 columns and 8 rows, as you can see in the images below. But in the matrix display, it is calculated from 0 to 7. The anode pins connect to the columns, and the cathode pins connect to the rows. We can control each LED individually by managing the electricity through the pairs of column and row pins. This allows us to display any type of character, making these displays very popular worldwide. Additionally, I connected one shift register to the anode pins and the other to the cathode pins, so we can control the display with just three pins. I also designed a PCB for this project, so you don’t have to worry about the wiring connections. You can download it with just one click and print it with JLCPCB using free coupons.

  • For more info about the Dot matrix display —  Click on me
How to make an 8x8 LED matrix display using an Arduino Nano

Ok, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s order PCBs for this project.

  • First, go to the JLCPCB official website and log in to your account.
  • If you are a new member to JLCPCB, please sign up using this link. Then you can get an $80 new user coupon.
  • Please register to get $80 Coupons — Click on me
  • Now, click the instant quote button and upload the Gerber file. You can download it using the link below.
  • Gerber file — Download
  • I have ordered five PCBs and a stencil. You can change the color and quantity as you like. Then, select the build time and shipping options. Finally, click the “Save to Cart” button.

Step 3

Thirdly, unbox your PCB and stencil package.

Step 4

Next, mount your PCB on a desk or any suitable surface. Then, place the stencil design on the PCB and apply the solder paste.

Step 5

Afterward, place the individual LEDs, resistors, and shift registers onto the PCB using a tweezer. Then, solder them using a hot air gun.

Step 6

Next, solder the female header and Pin terminal. Then connect the Arduino nano board to the PCB.

Step 7

Now, connect the Arduino board to the computer. Then, copy and paste the following program into the Arduino IDE.

How to make an 8x8 LED matrix display using an Arduino Nano
#include <FrequencyTimer2.h>

int SER_Pin = 10;      // Serial Data Input
int RCLK_Pin = 11;     // Storage Register Clock (Latch)
int SRCLK_Pin = 12;    // Shift Register Clock

#define number_of_74hc595 2
#define numOfRegisterPins number_of_74hc595 * 8

bool registers[numOfRegisterPins];
int py = 0;  // Y-axis (row) pointer

// 5x8 character set for letters A-Z and a space character (' ')
const byte charSet[27][5] = {
  {0x00, 0x00, 0x00, 0x00, 0x00},  // Space ' '
  {0x7E, 0x11, 0x11, 0x11, 0x7E},  // A
  {0x7F, 0x49, 0x49, 0x49, 0x36},  // B
  {0x3E, 0x41, 0x41, 0x41, 0x22},  // C
  {0x7F, 0x41, 0x41, 0x41, 0x3E},  // D
  {0x7F, 0x49, 0x49, 0x49, 0x41},  // E
  {0x7F, 0x09, 0x09, 0x09, 0x01},  // F
  {0x3E, 0x41, 0x49, 0x49, 0x7A},  // G
  {0x7F, 0x08, 0x08, 0x08, 0x7F},  // H
  {0x00, 0x41, 0x7F, 0x41, 0x00},  // I
  {0x20, 0x40, 0x41, 0x3F, 0x01},  // J
  {0x7F, 0x08, 0x14, 0x22, 0x41},  // K
  {0x7F, 0x40, 0x40, 0x40, 0x40},  // L
  {0x7F, 0x02, 0x0C, 0x02, 0x7F},  // M
  {0x7F, 0x04, 0x08, 0x10, 0x7F},  // N
  {0x3E, 0x41, 0x41, 0x41, 0x3E},  // O
  {0x7F, 0x09, 0x09, 0x09, 0x06},  // P
  {0x3E, 0x41, 0x51, 0x21, 0x5E},  // Q
  {0x7F, 0x09, 0x19, 0x29, 0x46},  // R
  {0x46, 0x49, 0x49, 0x49, 0x31},  // S
  {0x01, 0x01, 0x7F, 0x01, 0x01},  // T
  {0x3F, 0x40, 0x40, 0x40, 0x3F},  // U
  {0x1F, 0x20, 0x40, 0x20, 0x1F},  // V
  {0x7F, 0x20, 0x18, 0x20, 0x7F},  // W
  {0x63, 0x14, 0x08, 0x14, 0x63},  // X
  {0x03, 0x04, 0x78, 0x04, 0x03},  // Y
  {0x61, 0x51, 0x49, 0x45, 0x43}   // Z
};

// The message you want to scroll (now with spaces)
const char message[] = "LED MATRIX WITH ARDUINO NANO ";
const int scrollSpeed = 120;  // Speed of scrolling in milliseconds

unsigned long thisMs = 0;
unsigned long lastMs = 0;
int msgIdx = 0;  // Index for the message
int colIdx = 0;  // Column index for the current character

byte charBuffer[8];  // Holds the current 8 columns to be displayed

void setup() {
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);

  clearRegisters();
  writeRegisters();
}

void loop() {
  thisMs = millis();
  if (thisMs - lastMs > scrollSpeed) {
    lastMs = thisMs;
    scrollMessage();
  }
  displayMatrix();
}

void scrollMessage() {
  // Shift the buffer left
  for (int i = 0; i < 7; i++) {
    charBuffer[i] = charBuffer[i + 1];
  }

  // Load the next column from the current character in the message
  if (colIdx < 5) {
    if (message[msgIdx] == ' ') {
      charBuffer[7] = 0x00;  // Space character (blank)
    } else {
      charBuffer[7] = charSet[message[msgIdx] - 'A' + 1][colIdx];  // Map A-Z to the charSet
    }
  } else {
    charBuffer[7] = 0x00;  // Gap between characters
  }

  // Move to the next column
  colIdx++;
  if (colIdx > 5) {
    colIdx = 0;
    msgIdx++;
    if (message[msgIdx] == '\0') {
      msgIdx = 0;  // Loop back to start of message
    }
  }
}

void displayMatrix() {
  for (int row = 0; row < 8; row++) {
    clearRegisters();

    // Activate the row (anode)
    setRegisterPin(15 - row, LOW);

    // Set the column values (cathode)
    for (int col = 0; col < 8; col++) {
      if (charBuffer[col] & (1 << row)) {
        setRegisterPin(col, HIGH);
      } else {
        setRegisterPin(col, LOW);
      }
    }

    writeRegisters();
    delay(2);  // Small delay for persistence
  }
}

void clearRegisters() {
  for (int i = 0; i < numOfRegisterPins / 2; i++) {
    registers[i] = LOW;  // Clear anodes
  }
  for (int i = numOfRegisterPins / 2; i < numOfRegisterPins; i++) {
    registers[i] = HIGH;  // Set cathodes to HIGH
  }
}

void writeRegisters() {
  digitalWrite(RCLK_Pin, LOW);
  for (int i = numOfRegisterPins - 1; i >= 0; i--) {
    digitalWrite(SRCLK_Pin, LOW);
    digitalWrite(SER_Pin, registers[i]);
    digitalWrite(SRCLK_Pin, HIGH);
  }
  digitalWrite(RCLK_Pin, HIGH);
}

void setRegisterPin(int index, int value) {
  registers[index] = value;
}
  • Now, select the board and port. After, click the upload button. Also, you can change the text as you like.

Step 8

Afterward, disconnect the USB cable and provide a 5V power supply to the display. However, you can also power it using the USB cable.

Ok, enjoy this project! The full video guide is below. We hope to see you in the next project. Have a great day!

How to make an 8×8 LED matrix display using an Arduino Nano

Similar Posts

Leave a Reply

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