Arduino Nano - LED Matrix

This tutorial instructs you how to use Arduino Nano with LED matrix display. In detail, we will learn:

Once that is done, you can quickly adjust the code to suit other LED matrices such as 16x8 LED matrix, 64x8 LED matrix ...

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×FC-16 LED Matrix 32x8
1×FC-16 LED Matrix 8x8
1×Generic LED Matrix 8x8
1×Jumper Wires
1×DC Power Jack
1×5V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of LED Matrix

LED matrix displays are commonly referred to as LED displays or dot matrix displays.

LED Matrix display

LED Matrix come in many varieties. The MAX7219-based LED matrix is a popular choice for use with Arduino Nano. It has the following features:

  • Each block consists of an 8x8 LED matrix (64 LED) and a MAX7219 driver.
  • Two common block forms are the generic module and the FC-16 module.
  • A LED matrix can be made up of one or multiple blocks connected in a daisy-chain.
  • You can purchase pre-assembled LED matrices with multiple blocks (e.g. 4-in-1, 8-in-1).
  • Alternatively, you can buy individual blocks and wire them together to create a LED matrix of the desired size.
  • The size of the LED matrix used must be declared in the Arduino Nano code.

The LED Matrix Pinout

LED Matrix pinout

A LED Matrix is composed of one or more blocks. Each block has two sets of pins:

  • Input pins group:
    • VCC: connected to 5V power supply.
    • GND: connected to ground.
    • DIN: Data pin, connected to SPI MOSI pin of the Arduino Nano.
    • CS: Chip Select, connected to any digital pin of the Arduino Nano.
    • CLK: Clock pin, connected to SPI MOSI pin of the Arduino Nano.
  • Output pins group:
    • VCC: connected to VCC on the next block.
    • GND: connected to GND on the next module.
    • DOUT: Data Out, connected to the DIN pin of the next block.
    • CS: connected to CS on the next block.
    • CLK connected to CLK on the next block.

Wiring Diagram

If the LED matrix is made of a single block:

  • Attach the input pins groups to Arduino Nano
  • Leave the output pins group unconnected
The wiring diagram between Arduino Nano and 8x8 LED matrix FC-16

This image is created using Fritzing. Click to enlarge image

The wiring diagram between Arduino Nano and 8x8 LED matrix generic

This image is created using Fritzing. Click to enlarge image

If the LED matrix is pre-built of multiple blocks:

  • Connect the input pins group to Arduino Nano
  • Leave the output pins group unconnected
The wiring diagram between Arduino Nano and LED matrix display

This image is created using Fritzing. Click to enlarge image

If the LED matrix is made of multiple blocks by yourself:

  • Connect the input pins groups of the first block to Arduino Nano
  • Link the output pins groups of each block to the input pins groups of the following block
  • Leave the output pins group of the last block unconnected
Arduino Nano 32x8 LED matrix wiring FC-16 diagram

This image is created using Fritzing. Click to enlarge image

Due to the high current draw of the display (up to 1A at maximum brightness):

  • Do not power it from the 5V pin of an Arduino Nano.
  • Utilize an external 5V power supply instead. Both the Arduino Nano and LED matrix can be powered by a single 5V power adapter.

Since Arduino Nano is connected to the LED matrix through SPI pins:

  • Pin 13 (SCK) and 11 (MOSI) on Arduino Nano should be utilized. If a different Arduino Nano board is being used, consult the official documentation for the equivalent SPI pins.
  • Pin 3 (CS) can be altered to any pin on the Arduino Nano.

How To Program For LED Matrix

It is not a simple task to manage the LED matrix. Fortunately, libraries are available that make it much easier. Here is a step-by-step guide on how to write Arduino Nano code to control the LED matrix:

  • Include libraries:
#include <MD_Parola.h> #include <MD_MAX72xx.h>
  • Specify the type of hardware being used: GENERIC_HW or FC16_HW.
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
  • Specify the number of LED blocks used. For instance, a 4-in-1 LED matrix contains four blocks.
#define MAX_DEVICES 4
  • Specify the pin that is connected to the CS pin of the LED matrix. For example, pin D3.
#define CS_PIN 3
  • Create a MD_Parola object for the LED matrix display.
MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  • Code in the setup() function:
void setup() { ledMatrix.begin(); // initialize the object ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear led matrix display }
  • Show text, numerical values and animated effects: take a look at the following section

Arduino Nano - LED Matrix Code

This code is applicable for a 32x8 FC-16 LED matrix display consisting of four blocks. However, it can be adapted to 8x8, 16x8, 64x8 and other sizes with ease.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-led-matrix */ #include <MD_Parola.h> #include <MD_MAX72xx.h> #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 // 4 blocks #define CS_PIN 3 // create an instance of the MD_Parola class MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { ledMatrix.begin(); // initialize the object ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear LED matrix display } void loop() { ledMatrix.setTextAlignment(PA_LEFT); ledMatrix.print("Left"); // display text delay(2000); ledMatrix.setTextAlignment(PA_CENTER); ledMatrix.print("Center"); // display text delay(2000); ledMatrix.setTextAlignment(PA_RIGHT); ledMatrix.print("Right"); // display text delay(2000); ledMatrix.setTextAlignment(PA_CENTER); ledMatrix.setInvert(true); ledMatrix.print("Invert"); // display text inverted delay(2000); ledMatrix.setInvert(false); ledMatrix.print(1234); // display number delay(2000); }

Detailed Instructions

  • Connect Arduino Nano to the LED matrix as per the wiring diagram.
  • Connect the Arduino Nano to a PC using a USB cable.
  • Click to the Libraries icon on the left bar of the Arduino IDE.)
  • Look for “MD_MAX72XX” and then locate the MD_MAX72XX library.
  • Press the Install button.
  • Search for “MD_Parola”, then locate the MD_Parola library.
  • Press the Install button.
Arduino Nano MD_Parola library
  • You will be asked to install the “MD_MAX72XX” library
  • Click Install All button to install the dependency.
Arduino Nano MD_MAX72XX library
  • Copy the code and open it with Arduino IDE.
  • Click the Upload button on the IDE to send the code to the Arduino Nano.
  • Check out the LED matrix display the message.

Arduino Nano LED Matrix Code – Scrolling Text

If a message is too lengthy to be displayed on a LED matrix, the scroll text effect can be used. This technique allows the text to be scrolled across the display. The scroll text effect enables the message to be moved across the LED matrix, even if it is too long to fit.

This Arduino Nano code illustrates how to move a message across the LED matrix display.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-led-matrix */ #include <MD_Parola.h> #include <MD_MAX72xx.h> #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 4 // 4 blocks #define CS_PIN 3 // create an instance of the MD_Parola class MD_Parola ledMatrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); void setup() { ledMatrix.begin(); // initialize the object ledMatrix.setIntensity(0); // set the brightness of the LED matrix display (from 0 to 15) ledMatrix.displayClear(); // clear led matrix display ledMatrix.displayScroll("Hello", PA_CENTER, PA_SCROLL_LEFT, 100); } void loop() { if (ledMatrix.displayAnimate()) { ledMatrix.displayReset(); } }

To explore additional text effects, please refer to the MD_Parola Library Reference.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!