Turn on a LED Matrix with Arduino and MAX7219

Learn how to control an LED matrix using the MAX7219 controller and Arduino, ideal for creating animations, scrolling text, and graphics.

What is a LED Matrix?

An LED matrix is a rectangular display made up of multiple LEDs, commonly arranged in an 8x8 grid. These displays are ideal for showing scrolling text, animations, or simple graphics.

LED Matrix and MAX7219 Module

Price

8x8 LED matrices with a MAX7219 controller are affordable, typically costing around €1.27. These modules are easy to chain together to create larger displays.

How Does a LED Matrix Work?

LED matrices work by turning on individual LEDs at the intersection of rows and columns. To create complex graphics, the rows are scanned sequentially at high speed, using the principle of Persistence of Vision (POV) to make it appear that all LEDs are lit simultaneously.

LED Matrix Operation

Assembly Diagram

To connect a MAX7219 LED matrix to Arduino, use the following diagram:

Connection Diagram

For Arduino Uno and Nano, the SPI pins are 10 (SS), 11 (MOSI), and 13 (SCK).

Code Examples

Scrolling Text Example

This example uses the Max72xxPanel and Adafruit-GFX libraries to display scrolling text on 9 connected LED matrices:


#include 
#include 
#include 

// Connections:
// Vcc - Vcc
// Gnd - Gnd
// Din - MOSI (Pin 11)
// Cs  - SS (Pin 10)
// Clk - SCK (Pin 13)

const int pinCS = 10;
const int numberOfHorizontalDisplays = 9;
const int numberOfVerticalDisplays = 1;

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

String text = "Hello, Arduino!";  // Text to display
const int wait = 100;             // Delay in milliseconds
const int spacer = 1;             // Spacing between characters
const int width = 5 + spacer;     // Character width + spacing

void setup() {
    matrix.setIntensity(7);  // Set brightness (0 to 15)
    
    for (int i = 0; i < numberOfHorizontalDisplays; i++) {
        matrix.setPosition(i, i, 0);
        matrix.setRotation(i, 1);  // Adjust rotation if needed
    }
}

void loop() {
    for (int i = 0; i < width * text.length() + matrix.width(); i++) {
        matrix.fillScreen(LOW);

        int letter = i / width;
        int x = (matrix.width() - 1) - i % width;
        int y = (matrix.height() - 8) / 2;

        while (x + width >= 0 && letter >= 0) {
            if (letter < text.length()) {
                matrix.drawChar(x, y, text[letter], HIGH, LOW, 1);
            }
            letter--;
            x -= width;
        }
        matrix.write();
        delay(wait);
    }
}