Arduino Nano MAX7219 Simulator: Wiring, Code and a Live Circuit
This is an 8x8 LED matrix on a MAX7219 driver wired to an Arduino Nano, showing a heart live in your browser with the LedControl library and pulsing its brightness.
- 5 V logic
- Library: LedControl.h
- DIN 8, CLK 10, CS 9
- 8x8, intensity 0 to 15
Wiring the MAX7219 to the Arduino Nano
Five wires: 5 V, ground, and DIN, CLK and CS to pin 8, pin 10 and pin 9.
Every connection in the circuit above, with the board’s own pin names.
| MAX7219 pin | Arduino Nano pin | Why |
|---|---|---|
| VCC | 5V | The MAX7219 runs from 4 to 5.5 V; the module is a 5 V part. |
| GND | GND | Common ground. |
| DIN | pin 8 | Data into the chip, clocked in one bit at a time. |
| CS | pin 9 | Chip select, also called LOAD: it latches the bits into the display. |
| CLK | pin 10 | The clock that moves each bit of DIN in. |
Power
The module takes 5 V from the Arduino Nano’s 5V pin and its inputs read the board’s 5 V signals directly. A full 8x8 matrix at maximum brightness draws a few hundred milliamps, so keep the intensity low or give it its own 5 V supply.
Pins to leave alone on the Arduino Nano
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
On a real bench
The Nano plugs into the breadboard itself, straddling the center channel, so the MAX7219 goes in a few columns along and every connection is a short jumper. The silkscreen labels its pins D2 to D13 and A0 to A7; in code D2 is simply 2. A Nano clone with a CH340 USB chip needs that driver on a real computer.
The code, and what it does.
The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.
#include <LedControl.h>
const int DIN_PIN = 8; // pin 8
const int CLK_PIN = 10; // pin 10
const int CS_PIN = 9; // pin 9
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, 1); // one 8x8 block
// A heart, one byte per row, top row first.
const byte HEART[8] = {
B00000000, B01100110, B11111111, B11111111,
B11111111, B01111110, B00111100, B00011000,
};
void setup() {
Serial.begin(9600);
lc.shutdown(0, false); // wake the chip up
lc.setIntensity(0, 4); // 0 to 15
lc.clearDisplay(0);
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, HEART[row]);
}
Serial.println("Matrix ready");
}
void loop() {
lc.setIntensity(0, 2);
delay(500);
lc.setIntensity(0, 12);
delay(500);
}
LedControl lc(DIN, CLK, CS, 1) bit-bangs the chip’s three-wire interface on any three pins and says there is one 8x8 block. shutdown(0, false) wakes the chip, which powers up asleep, and clearDisplay() blanks it.
setRow() writes one row of eight LEDs as a byte, so the HEART table is the picture, one byte per row, top row first. The chip keeps the picture and refreshes it itself, so the sketch only has to write it once.
setIntensity() takes 0 to 15, and the loop moves it between 2 and 12 so you can see the brightness change.
Common mistakes with the MAX7219 on the Arduino Nano
Forgetting to wake the chip
The MAX7219 starts in shutdown mode with the display off. Without lc.shutdown(0, false) every row you write goes in and nothing lights.
Mixing up DIN and DOUT
DIN is the input end of the module. DOUT is the output to the next block in a chain. Wired to DOUT, the board talks to nothing.
Running the matrix at full brightness from USB
Sixty-four LEDs at intensity 15 draw several hundred milliamps. Keep the intensity low in code, or power the module from its own 5 V supply and join the grounds.
Questions and answers
How do I connect a MAX7219 matrix to an Arduino Nano?
Power it from 5V and GND, and wire DIN, CLK and CS to pin 8, pin 10 and pin 9. Then create an LedControl with those pins in that order, DIN first.
Which library should I use?
LedControl is the simplest and is what this page uses. MD_MAX72XX adds scrolling text and several block types, and wires the same way.
Why is the picture mirrored or turned?
Modules are wired differently. Reverse the bits of each row to mirror it, or write the rows in reverse order to flip it.
Can I chain more than one block?
Yes. Join each module’s DOUT to the next one’s DIN, share CLK and CS, and give LedControl the number of blocks. In the editor, set the part’s count property.
Build your own MAX7219 project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.