A collection of examples for driving displays from microcontrollers

Display Technologies
Driver Technologies
Control Protocols
Display Libraries for Arduino
TFT LCD Examples
OLED Examples
ePaper Examples
8x8 LED Matrix examples
QR Code Examples

This project is maintained by tigoe

8x8 LED Matrix Displays

8x8 LED matrixes are made up of 64 LEDs in a single package, with their anodes and cathodes arranged in a matrix for row-column scanning. An 8x8 matrix requires 16 digital pins from a microcontroller to operate it. Many LED manufacturers make this common display.

Photo of an 8x8 LED Display

Figure 1. 8x8 LED Display. Image from Digikey.com

The circuit for these displays is shown in Figure 2. There are 8 supply pins, each connected to the anodes of 8 LEDs. There are also 8 ground pins, each connected to the cathodes of 8 LEDS. The LEDs are arranged in a grid, so that one LED from each supply line is attached to each of the ground lines. The pin numbers for the rows and columns will vary depending on the model and manufacturer, so see the data sheet of your particular display to get the right pin numbers.

Schematic of an 8x8 LED Display

Figure 2. Schematic of an 8x8 LED Display.

Breadboard view of an 8x8 LED matrix connected to an Arduino Nano 33 IoT

Figure 3. Breadboard view of an 8x8 LED matrix connected to an Arduino Nano 33 IoT. The rows are connected to pins D2 through D9. The columns are connected to pins A0 through A7.

When you connect a given supply line to voltage, and a given ground line to ground, then the LED corresponding to those two pins will light up. To control all the LEDs, you scan over the rows and columns like so:

Store the intended states of the LEDs in an array 

  loop over the columns  
    take this column high
    take all the rows high 
      loop over the rows
        Read the LED’s state from the array
        If this LED should be on,  
          Take this row low 
      End row loop
    Take this column low 
  End column loop
end loop

quoted from Physical Computing, p. 397

This algorithm translates directly to code, as seen in the Arduino example below:

// set the row and column pin numbers:
int col[] = {6, A2, A3, 3, A5, 4, 8, 9};
int row[] = {2, 7, A7, 5, A0, A6, A1, A4};

void setup() {
  // initialize all the pins as outputs:
  for (int i = 0; i < 8; i++) {
    pinMode(row[i], OUTPUT);
    pinMode(col[i], OUTPUT);
    // set the column pins HIGH:
    digitalWrite(col[i], HIGH);

void loop() {
  // take the rows high:
  for (int r = 0; r < 8; r++) {
    digitalWrite(row[r], HIGH);
    // Take each column low to turn on (row, column):
    for (int c = 0; c < 8; c++) {
      digitalWrite(col[c], LOW);
      // take the col high to turn off the LED:
      digitalWrite(col[c], HIGH);
    // take the row low to turn off the whole row:
    digitalWrite(row[r], LOW);

This repository contains several examples: