Using a 74HC595 to control a LED Matrix

Rodrigo Sousa Coutinho
Arduino Playground
Published in
3 min readMar 5, 2017

Setting up a LED Matrix can quickly get you out of pins to do other things with your Arduino. One way to overcome this is to use a 74HC595 shift register.

This chip transforms bits that are inserted in series trough the data pin into 8 parallel bits. More on that later, but first, the circuit:

The chip in the middle is the one doing the magic!
The chip in the middle is the one doing the magic!

The connection between Arduino and the matrix columns is the same as without the 595. Just plug it to the right pins with a resistor in the middle (I used a 330Ω) and you’re done.

Pins QA-QH on the 595 are the outputs that we want, so they’re connected to the matrix rows. Don’t worry about QH*.

The other interesting pins are:

  • SER (SERial) where the data gets in;
  • SRCLK (SeRial CLocK) the pin you set to high to store what’s in SER;
  • RCLK (Register CLocK) the pin you set to high once you’re done setting all the pins.

So here’s how it works. Let’s imagine you want to set the QA-QH to 10010010. You start with the least significant bit (0) so you set SER to LOW (D10 on the Arduino). Next, you set SCK (D11 on the Arduino) to HIGH and then to LOW, to “save” the value.

Time to go to the second bit, which has value 1. So you set SER to HIGH, and again you set SCK to HIGH and then to LOW.

You keep going, until you’ve sent the 8 bits. At this point, you set the RCLK to HIGH to sent your changes to pins QA through QH.

This may seem complex, but fortunately Arduino has a function that takes care of sending that bits out to the shift register:

shiftOut(dataPin, clockPin, bitOrder, value)

This means that, to set data on the 595, all you have to do is:

digitalWrite(RCK_PIN, LOW); 
// Write byte_to_write to SER, using SCK_PIN as the clock and
// send the least significant byte first (LSBFIRST)
shiftOut(SER_PIN, SCK_PIN, LSBFIRST, byte_to_write);
digitalWrite(RCK_PIN, HIGH);

Cool, isn’t it?

So here’s the full code for the LED matrix, using a 595:

If you run this code you’ll get a nice smile! If you want to build a different character, head over to the character builder and create your own.

You can get the code and schematics for this project on github.

--

--

Rodrigo Sousa Coutinho
Arduino Playground

Hi! I’m co-founder and Director of Data Science at OutSystems, with a passion for data, great products, and geeky stuff!