Built-in project · Arduino Uno R3

MAX7219 8x8 matrix (pins 12, 10 and 11), on an Arduino Uno

An 8x8 LED matrix on a MAX7219 module with DIN on pin 12, CLK on 10 and CS on 11: LedControl draws a smile, a frown and a heart in turn. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $33. On Mokxi they're free.

MAX7219 8x8 matrix (pins 12, 10 and 11) · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • Driving an LED matrix with a MAX7219
  • Sending data on three wires: DIN, CLK and CS
  • Storing a picture as one byte per row
  • Using the LedControl library
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Arduino Uno R3
  • Parts: 3

How it works

An 8 by 8 matrix has 64 LEDs, far too many to wire to one board. A MAX7219 chip on the module does the scanning itself. The Uno sends it data over three wires: DIN on pin 12, CLK on pin 10 and CS on pin 11.

Each picture is eight bytes, one per row. The leftmost LED in a row is the top bit. The sketch holds three pictures: SMILE, FROWN and HEART.

The loop shows each one for one second, in that order, and prints its name to the serial monitor.

Parts list

3 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.

Kits that can build it

This starter kit has every part in the circuit. Each kit's page lists what else it can build.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
LED matrix, 8x8 pin GNDArduino Uno R3 pin GND
LED matrix, 8x8 pin DINArduino Uno R3 pin 12
LED matrix, 8x8 pin CSArduino Uno R3 pin 11
LED matrix, 8x8 pin CLKArduino Uno R3 pin 10
LED matrix, 8x8 pin VCCArduino Uno R3 pin 5V

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// An 8x8 LED matrix on a MAX7219: three faces, one after another.
//
//   MAX7219 DIN -> pin 12    CLK -> pin 10    CS -> pin 11
//   MAX7219 VCC -> 5V        GND -> GND
//
// Sixty-four LEDs would need sixty-four pins driven directly. The MAX7219
// scans the rows itself; the Uno only sends it one byte per row over three
// wires. LedControl does the sending. Its constructor takes DIN, CLK, CS and
// the number of modules chained together.
//
// Each picture is eight bytes, one per row, with the leftmost LED in the top
// bit. Draw your own on squared paper and type it in.

#include <LedControl.h>

LedControl lc = LedControl(12, 10, 11, 1);

const byte SMILE[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
const byte FROWN[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};
const byte HEART[8] = {0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18};

void draw(const byte *picture, const char *name) {
  for (int row = 0; row < 8; row++) lc.setRow(0, row, picture[row]);
  Serial.println(name);
}

void setup() {
  lc.shutdown(0, false);  // the module starts asleep
  lc.setIntensity(0, 8);  // 0 to 15
  lc.clearDisplay(0);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: MAX7219 on pins 12 (DIN), 10 (CLK) and 11 (CS)");
}

void loop() {
  draw(SMILE, "smile");
  delay(1000);
  draw(FROWN, "frown");
  delay(1000);
  draw(HEART, "heart");
  delay(1000);
}

Code walkthrough

The key functions of the sketch, and what each one does.

draw sketch.ino

It takes a picture and a name. A loop sends each of the eight bytes to the matching row with lc.setRow. Then it prints the name to the serial monitor. Changing the bytes in a picture changes what lights up.

void draw(const byte *picture, const char *name) {
  for (int row = 0; row < 8; row++) lc.setRow(0, row, picture[row]);
  Serial.println(name);
}

setup sketch.ino

The module starts asleep, so lc.shutdown(0, false) wakes it. Then lc.setIntensity sets brightness to 8 on a scale of 0 to 15, and lc.clearDisplay blanks the LEDs. It also starts the serial port at 9600.

void setup() {
  lc.shutdown(0, false);  // the module starts asleep
  lc.setIntensity(0, 8);  // 0 to 15
  lc.clearDisplay(0);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: MAX7219 on pins 12 (DIN), 10 (CLK) and 11 (CS)");
}

loop sketch.ino

It calls draw for the smile, the frown and the heart. After each one it waits 1000 ms, then starts over.

void loop() {
  draw(SMILE, "smile");
  delay(1000);
  draw(FROWN, "frown");
  delay(1000);
  draw(HEART, "heart");
  delay(1000);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The matrix stays dark. This project
    Check DIN is on pin 12, CLK on pin 10 and CS on pin 11, with VCC on 5V and GND on GND. The sketch must also wake the module with lc.shutdown(0, false).
  • The picture looks mirrored or upside down. This project
    Check the order of the bytes in the picture. The first byte is the top row, and the top bit is the leftmost LED.
  • The matrix is blank after upload. LED matrix
    On power up the MAX7219 is in shutdown mode with intensity 0. Wake it, set intensity, set scan limit to all 8 digits, and clear the display.
  • Dim, flickering, or wrong rows. LED matrix
    Set the ISET resistor right for your LEDs (about 10 kohm for 40 mA). Power from 5 V with a 0.1 uF capacitor, and chain DOUT to the next DIN.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.