Introduction: LED Matrix With Arduino

Hola , I am Javier from Makespace Madrid. Last week we organised a meetup to play with LED matrixes and Arduinos. This was part of  "La noche de la electrónica con Jameco"
This instructable is based on the workshop. It uses one single LED matrix and shows how to switch its LEDs on/off and how to display ASCII characters.
A future instructable will show how to work with mulitple LED matrixes connected together.

Step 1: Components

For this example, you need the following components:
- Arduino Uno board
- MAX7219 Red Dot Matrix Module
- 5 jumper wires F/M (female/male)

Although this instructable uses an Arduino Uno board, you can use other Arduino (compatible) boards

You can find the matrix module at many online stores (e.g. http://dx.com/p/max7219-dot-matrix-module-w-5-dupont-lines-184854). This includes a 8x8 LED matrix (red colour), a MAX7219 chip to control the LEDs, header PINs and sockets, one 10KOhm resistor, a 100nF capacitor, a 10uF electrolic capacitor and a PCB where everything is connected together. You can purchase the module already soldered and mounted or just the components. Up to you;-)

If you want to learn the low level details, you should check this article at arduino playground.

IMPORTANT: The LED matrix is common cathode. This module does not work with common anode matrixes.

Step 2: Arduino Library

The LED matrix is controlled from the MAX7219 chip through an Arduino Library.
This instructable is based on the LEDControl library. You can read a very clear and detailed tutorial about this library at arduino playground.
The nice thing about this library is that you can connect up to 8 matrixes together to build larger displays (more about this in a future instructable).

The LedControl library has been updated with several new methods to simplify the display of characters and strings. The new version of the library is available here (chose your preferred compression format: zip or rar)

To install the library in your Arduino IDE:
- uncompress the library file that you just downloaded
- make sure that you close all the open windows of the Arduino IDE
- look for the libraries folder inside the folder where you installed the Arduino IDE (see picture)
- copy the uncompressed LedControlMS folder (the folder with all its content)  inside the libraries folder


If everything worked fine, you can now open the Arduino IDE again. If you go to File-> Examples, there should be a tab named LedControlMS with four files inside it.

Step 3: Wiring

Once you have installed the library, it is time to connect the LED matrix to the Arduino board.

The LED Matrix module has two sets of male header PINs. In this instructable you will only use the input PIN headers that are located closer to the MAX 7219 chip.
There are five PINs that must be connected through F/M jumper wires to the corresponding Arduino PINs:

LED Matrix        Arduino         Colour of wire in picture
VCC                        5V                       Red
GND                       GND                   Black
DIN                         D12                    Yellow
CS                          D10                     White
CLK                        D11                     Blue

You can check the colours of the wires in the pictures in case that you have any doubt.

Step 4: Example Sketch

The original LedControl library can handle both 7-segments LED displays as well as LED matrixes. This instructable only uses the LED matrix methods.

The updated library created for the Makespace Madrid workshop defines an alphabet/font of characters that can be displayed in the LED matrixes. It also includes two new methods, writeString and displayChar. You can see practical examples of how the different methods work in the MakeSpace_LEDMatrix example sketch distributed with the library.
To open this sketch, in the Arduino IDE menu go to File-> Examples->LedControlMS->MakeSpace_ LEDMatrix

You can now upload the sketch to your arduino and see what the example does.

Note1: if the version of your Arduino IDE is "quite" old (0.x) you will need to change the extension of the arduino sketches distributed with the library. Change the extension of the files from .ino to .pde (MakeSpace_ LEDMatrix.ino -> MakeSpace_ LEDMatrix.pde). Your IDE should be able to read and open this file (probably you need to close all the Arduino IDE windows, change the file extensions and then restart the IDE again).

Note2: Before uploading the sketch, make sure that you have selected the right card and serial port for your arduino

Step 5: And Play!

If everything worked fine, your LED matrix will start a sequence of actions switching on and off leds and displaying different characters.
You can now map the code in the example sketch to the actions in the matirx. Update the sketch to do new things and experiment with  the library methods.

To help you, the PDF file below has some hints about how the LEDs, rows and columns are numbered and coded in the LEDControl library.
Don't be afraid to make errors! That is the fastest way to learn.

Enjoy!

Comments

author
MalcolmO5 (author)2017-08-12

#define NBR_MTX 2 // Why do I have to say "2" when there is only 1 matrix in my setup?

author
tumaku (author)MalcolmO52017-08-21

Thanks Malcolm for noticing this bug!

I used the same sketch for another project with multiple matrices and I forgot to set NBR_MTX back to "1". Anyway, since the code only references one matrix (the one with index "0") the sketch is still working without any problem.

author
gooleim (author)2017-08-21

I CAN'T FIND THE CODE!?

author
tumaku (author)gooleim2017-08-21

There is a link in step 2 to compressed files in zip and rar format.

author
NoahP5 (author)2015-07-09

I am only getting two leds showing at once. I have checked for bridges and there are none. Can anyone help me here?

author
NoahP5 (author)NoahP52015-07-10

I am now getting more LEDs on at once but no distinguishable letters.

IMG_0219.JPG
author
Attila_FIN (author)NoahP52017-04-17

Hello, Most probably you fixed the LED matrix on the wrong side of the PCB.
It might be soldered on the CHIP side of the PCB.

author
MrMonk (author)NoahP52016-02-14

I had the same /similar problem. the reason was that the MAX7219 was wrong inserted. I just removed it and inserted it in the other way round. Then it works!

author
tumaku (author)NoahP52015-09-14

Sorry for the late response.

Not sure what is wrong, but I suggest to check three points:

- Are you providing enough power (miliamps) to the matrix?

- Have you double/triple checked that the wires are properly connected?

- Are you using a common cathode matrix? (the code does not work if the matrix is common anode)

author
goldenshuttle (author)2017-04-08

nice work. Will this code run on USB attiny85 ?

author
TomK32 (author)goldenshuttle2017-04-17

Sure it does. The ATTiny85 has plenty of pins for this. Even though it has only eight.
https://www.instructables.com/id/V-USB-ATtiny85-Pro...
https://halfbyteblog.wordpress.com/2015/11/29/usin...

author
D6equj5 (author)2017-02-21

hi, can the max7129 be used for a dot matrix display with an Arduino pro Micro? If so, What would be suitable pin connections?

author
tumaku (author)D6equj52017-02-21

I have used it with an Arduino ProMini so a ProMicro should also be ok. The pins in the instructable are defined as:
LED Matrix    Arduino          Colour of wire in picture
VCC               5V                   Red
GND              GND                Black
DIN                D12                 Yellow
CS                 D10                 White
CLK               D11                 Blue

You can remap them for your ProMicro by updating their values in the following line of the sketch:

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

author
trancor (author)2017-02-06

Hey Tumaku, thanks for your post! This helped me out a ton when I first started out with my 8x8 Matrix.

I've linked to your instructables in an INO I made to make it easier to animate moving animations on the MAX7219 8x8 LED Matrix. I think I need to comment more of the code here, but the basics are there.

https://github.com/ProcStack/Arduino/tree/master/L...

Here's what the animation looks like (Sorry, it might be a little loud.)

author
tumaku (author)trancor2017-02-14

Cool animations!

author
PCSolid made it! (author)2016-06-02

Made this using breadboard for interconnect... Simple, flawless! Works GREAT! Recent Computer Science graduate, played with image matrix binaries to make happy/sad face animation... The binary creator at http://www.pial.net/tools/ helps a LOT! Thnx for posting!

318.MOV316.JPG314.JPG
author
BenW110 (author)PCSolid2017-01-14

Thanks a lot for that website! That really speeds up the most tedious part of coding these things!

author
tumaku (author)PCSolid2017-01-10

Great! Thanks for sharing the result :)

author
suyogd9 (author)2016-12-29

can i get code or any information for respective project ?

author
tumaku (author)suyogd92017-01-10

Code and explanation is available in Step 2

author
Khuzzai (author)2017-01-10

can you give me sketch(coding) in arduino ? khuzzair@gmail.com :D Thanks

author
tumaku (author)Khuzzai2017-01-10

Code and explanation is available in Step 2

author
PCSolid made it! (author)2016-06-02

Made this using breadboard for interconnect... Simple, flawless! Works GREAT! Recent Computer Science graduate, played with image matrix binaries to make happy/sad face animation... The binary creator at http://www.pial.net/tools/ helps a LOT! Thnx for posting!

318.MOV316.JPG314.JPG
author
tumaku (author)PCSolid2016-06-02

:-)

author
PCSolid made it! (author)2016-06-02

Made this using breadboard for interconnect... Simple, flawless! Works GREAT! Recent Computer Science graduate, played with image matrix binaries to make happy/sad face animation... The binary creator at http://www.pial.net/tools/ helps a LOT! Thnx for posting!

318.MOV316.JPG314.JPG
author
piyush26 (author)2016-03-23

Hii,

I have different type of matrix tube.I want to program it using Arduino Uno R3. I have attached the photo of my 8*8 Dot Matrix Led Tube

Matrix.jpeg
author
Jamsel (author)2016-02-26

Thanks this is a great tutorial. I learnt a lot from it!

author
tumaku (author)Jamsel2016-02-26

Keep learning :-)

author
tumaku (author)2016-01-28

The method setRow updates the on/of state of all the LEDs in a row of a matrix.

setRw (matrixIndex, rowIndex, vlaue)

Note that matrixIndex and rowIndex start at zero.

In your case, you are setting value 0xC0 for row 1 of matrix 0.

How is the value coded? It is an 8-bit binary number where each bit represents the state of a LED in the row (0 for off state and 1 for on state).

0x0C (hexadecimal)= B00001100 (binary)

This means that there are only two LEDs on in this row (the ones at position 3 and 4 starting from the right)

author
kantona80 made it! (author)2016-01-23

I updated the library to display smiles 8x8 using lc.displaySmile(0,X); function replace X with a number from 0 to 3 (I added only 4 smiles).

you can download it from here:

https://drive.google.com/file/d/0B0rVZYzj6RpOcFF1U...

to display them copy this code into you loop:

void loop() {
lc.clearDisplay(0);
lc.displaySmile(0,0);
delay(2000);
lc.clearAll();
lc.displaySmile(0,1);
delay(2000);
lc.clearAll();
lc.displaySmile(0,2);
delay(2000);
lc.clearAll();
lc.displaySmile(0,3);
delay(2000);
lc.clearAll();
}

you can custom these smiles (or add other 8x8 icons) using this online tool: http://www.pial.net/tools/ and paste them into the LedControlMS.h file, under the declaration of smileBitmap matrix (also remember to change size of const static byte smileBitmap if you add or remove items).

c15b5745c394351ebd32eba741520250.jpg24818a2933c362eeacb3bf8db35918dd.jpg
author
tumaku (author)kantona802016-01-23

Great update to the library!!! And excellent link to code bitmaps:-)

author
kantona80 made it! (author)2016-01-23

thanks

foto 1.JPGfoto 2.JPGfoto 3.JPG
author
joshual40 (author)2016-01-17

When I use 5 matrices only four of them display letters, but when I reset they all light up and then go back to only 4, I already edited the code to 5 MTX. Help plz

author
WhittlinThom made it! (author)2016-01-02

I did this one before but didn't have any luck with changing the message. this time I was able to change it but I couldn't figure out how to slow it down so it is more readable. Any suggestions? I really need someone that would be willing to help me from time to time.

temp_-991635396.jpg
author
tumaku (author)WhittlinThom2016-01-03

If you lare using the method writeString() to display your text, you should modify this method in the corresponding library flle (LedControlMS.cpp). This method waits 300 milliseconds after displaying a character. You can meke this dealy longer just changing '300' value by your desired delay, e.g. delay(1000) if you want to wait for one second.

void LedControl::writeString(int mtx, char * displayString) {
while ( displayString[0]!=0) {
char c =displayString[0];
int pos= getCharArrayPosition( c);
displayChar(mtx,pos);
delay(300);
clearAll();
displayString++;
}
}
author
MichelleP67 (author)2015-11-26

my frend i need your help, i do all what you did, but when i run the program all the led always are ON and i can't turn them Off. why? i have to increment the intensity to 15 and i can si how the text is moving but other leds always are ON.

author
tumaku (author)MichelleP672015-11-26

One possible cause is the wrong connection of the wires. Please double-check that you have connected the right PINs in Arduino/LED matrix and that the wires are in good state.

It could also be that you soldered something wrong in the board or that one of the PINS in the matrix is broken or bended.

author
MichelleP67 (author)tumaku2015-11-26

di you speak spanish? can you say me you facebook or email to contact to you? thank you.

author
wilfrid.defontaine made it! (author)2015-11-06

that's great.

temp_599871459.jpg
author

Congratulations :-)

author
nodoubtman (author)2015-10-12

Your library really rocks, congratulation :))

author
tumaku (author)nodoubtman2015-11-06

:-)

author
laserlevi (author)2015-06-05

How do I make the text scroll smoothly across a single matrix?

Because with the sketch I have now (yours), the letters will just appear and dissapear on the same position.

I hope you can help me!

author
tumaku (author)laserlevi2015-09-14

Sorry for the late reply. The library does not support smooth scrolling. You need to update it addding scrolling functionality (handle every letter/char as a set of pixel columns that scroll over the 8 columns of the matrix). Not difficult, but it requires some coding.

author
NoahP5 (author)laserlevi2015-07-12

Just use the code from the other Instructable and change #define NBR_MTX 4 to #define NBR_MTX 1

author
EEEngineer (author)2015-09-14

How would I make a 16 row display,... please advise....

my email is eng.gachara@gmail.com

author
tumaku (author)EEEngineer2015-09-14

It is a long time since I made this project, but as fas as I can remember the maximum number of matrices supported by the library and the MAX7219 chip is 8. I tested it in the past and it worked fine. I just had to provide enough power ideally with an external power source other than Arduino (when many LEDS are ON Arduino cannot provide enough miliamps and things start going wrong)

8 marices make 64 x 8 LEDS. If you need a larger display, the current library is not suitable and you need to either synchronise somehow two sets of matrices or dig into the curent library code and see if you can update it to control two sets of matrices (i.e. 16 matrices)

author
Riscyg (author)2015-05-28

Excellent stuff, very clear and easy to follow - thanks a lot.

I have a bunch of matrices lying around and will definitely be doing your other 'ible :)

author
tumaku (author)Riscyg2015-05-29

Thanks for trying it out:) Have fun!

author
greenbriel (author)2015-05-14

I soldered up a MAX7219 kit ($8 with prime shipping on Amazon - constantly amazes me how cheap things are these days) and this instructable was exactly what I needed next. Just wanted to say thanks!

About This Instructable

367,637views

270favorites

License:

More by tumaku:Multiple LED Matrices with ArduinoLED Matrix with Arduino
Add instructable to: