Wiring guide

How to wire a MAX7219 LED matrix to an Arduino Mega

To wire a MAX7219 LED matrix to an Arduino Mega, connect VCC to 5V, GND to GND, DIN to pin 8, CS to pin 9 and CLK to pin 10. The module runs from the 5 V pin and the Arduino Mega’s 5 V signals drive it directly. The sketch below uses the LedControl (LedControl.h) library. It shows a heart on the 8x8 matrix and pulses its brightness.

  • 5 V logic
  • Library: LedControl.h
  • 5 wires
Arduino Mega · MAX7219 LED matrixlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

MAX7219 LED matrix to Arduino Mega wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

MAX7219 LED matrix pinArduino Mega pinWire colorWhy
VCC5VredThe MAX7219 runs from 4 to 5.5 V; the module is a 5 V part.
GNDGNDblueCommon ground.
DINpin 8greenData into the chip, clocked in one bit at a time.
CSpin 9amberChip select, also called LOAD: it latches the bits into the display.
CLKpin 10violetThe clock that moves each bit of DIN in.
Voltage

Power and logic levels for MAX7219 LED matrix and Arduino Mega

Logic level

The Arduino Mega’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

Supply

The MAX7219 LED matrix takes 5 V from 5V. That is the Arduino Mega’s 5 V rail, so the part shares the current the board can supply.

This pair

The module takes 5 V from the Arduino Mega’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

Pins 14 to 19 are the three extra serial ports and 20 and 21 are I2C, so keep them free if you will need those. An Uno shield’s I2C on A4 and A5 is not connected to anything on a Mega.

The sketch

The working code for the Arduino Mega

Library: LedControl (LedControl.h). This is the sketch the circuit above runs.

MAX7219 matrix on Arduino Mega pin 8, pin 10, pin 9
#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);
}
Output

What you should see

The matrix shows a heart whose brightness steps between dim and bright every half second. The serial monitor, at 9600 baud, prints Matrix ready once.

A dark matrix with power on means the chip is still in shutdown: the sketch must call shutdown(0, false) first.

The serial monitor prints this, recorded from the circuit above running:

Matrix ready
Pitfalls

Common mistakes wiring a MAX7219 LED matrix to an Arduino Mega

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.

Build your own MAX7219 LED matrix project

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