Multiplexing with Arduino and the 74HC595

The 74HC595 is an easy and inexpensive (at about 60 cents apiece) way to increase the number of digital out pins on your Arduino.  In this tutorial I’ll show you how to drive up to 16 LEDs with one 74HC595 using a technique called multiplexing.  In the end, all 16 LEDs will require only three of the Arduino’s available digital pins.

The finished product will look like this:

I used the sparkfun button pad pcb to build my 4×4 led matrix because this is the first step in a longer project I’m working on that involves backlit buttons.  However, you can build your own 4×4 led matrix pretty easily on a breadboard, and I’ll provide schematics that will show how to do that.  My parts list is given below:
Parts List:

SPARKFUN:
(1x) Button Pad 4×4 – LED Compatible Sparkfun COM-07835
(1x) Button Pad 4×4 – Breakout PCB Sparkfun COM-08033
(1x) Arduino Uno Sparkfun DEV-11021

DIGIKEY (you could find these at Jameco):
(16x) White 5mm LED (3mm is fine too) Digikey C513A-WSN-CV0Y0151-ND
(1x) 74HC595 shift register Digikey 296-1600-5-ND
(1x) 16 pin IC socket Digikey A100206-ND

JAMECO:
(1x) 16 conductor ribbon cable Jameco 28RC16-10VP
(1x) 16 pin right angle connector Jameco 746285-3
(2x) male header pins Jameco 7000-1X40SG-R

Additional Materials:
22 Gauge Wire, multiple colors Radioshack #278-1221
protoboard with copper Radioshack #276-147
wire cutters
wire strippers
solder

Step 1: What Is Multiplexing?

Multiplexing with Arduino and the 74HC595
Multiplexing is a very efficient technique for controlling many components wired together in a matrix/array.  In this example, I’ll be talking exclusively about multiplexing an array of LEDs, but the same basic principles apply to other multiplexed components (sensors, buttons, etc).

In a multiplexed array of LEDs, only one row of LEDs is on at any given time.  It seems like this would limit the types of shapes we can display on the LED matrix, but it actually doesn’t.  This is because the arduino (or whatever is sending data to the array) is switching through each row so quickly (hundreds or thousands of times a second) that we do not perceive the flashing on and off of each consecutive row.  You can read more about this phenomenon, called persistence of vision, on wikipedia.

So how do we send data to one row at a time?  If we connect five volts (red) to one row and connect ground (blue) to the other three rows and cycle through each row one by one, it will look something like figure 1.  Now image that while one of the rows is at +5, we connect one of the columns to ground.  As shown in figure 2, this will cause the LED at the junction of the +5 row and GND column to light up.  This way, we can address each of the 16 LEDs in the matrix individually using only eight leads (four to the rows and four to the columns).

Now look at the image below.  Imagine if we very quickly turn on the LED in the upper left corner (position 1,1), then the LED at (2,2), then (3,3) and (4,4), and we cycle between these four LEDs very quickly (hundreds of times a second).  It will appear that all four of these LEDs are on a the same time (as shown in right image in the image below).  Study the diagram below and convince yourself that this is true.

Step 2: How does the 74HC595 work?

The 74HC595 is an 8 pin shift register.  Shift registers are chips which use logic gates to control many inputs or outputs at once.  They are inherently digital, like the digital pins on the arduino- this means that they can only read or write 0V and 5V (low or high), they should not be used to read analog data from sensors or potentiometers (instead consider using a mux/demux such as the 4051).  The 74HC595 has 8 outputs labeled Qa-Qh (or Q0-Q7), it cannot read data from these pins, they can only be used as outputs (if you are looking for a shift register with inputs check out the 74HC165).

The 74HC595 is controlled by three connections to the arduino (or your microcontroller of choice); they are called the data pin, latch pin, and clock pin.  Refer to the flow diagram above (figure 1):

-first the latch pin is set to ground to disable the outputs, this way the output pins won’t change as we are sending in new data to the 74HC595
-next new data is sent to the 74HC595 serially, by pulsing the clock pin and sending each byte of new data out the data pin bit by bit.  Arduino has a handy function in their library called shiftOut that takes care of this for you.
-finally, set the latch pin high.  This sends your new data to all the output pins at once (parallel output).

In this tutorial I’ll show you how to control a 4×4 LED matrix with one 74HC595.  In the previous step I showed that it is possible to control a 4×4 LED matrix using only 8  pins (four for the rows and four for the columns).  In the next steps I’ll show you how to wire the 4×4 LED matrix to the 8 output pins of the 74HC595 and drive the entire thing with the arduino.

One more thing to add about the 74HC595:
It is also possible to expand your outputs even further by daisy chaining 74HC595, but that is outside the scope of this tutorial.

Step 3: Schematic

The images above show the schematic for the LED matrix and 74HC595 circuit.  The labels in fig 2 correspond to the labels on the sparkfun button pad.  Figure 3 is the pin diagram of the 74HC595 from the chip’s datasheet.

Arduino Pin Connections to 74HC595

A0    Clock Pin (pin 11)
A1    Latch Pin (pin 12)
A2    Data Pin (pin 14)

Multiplexing with Arduino and the 74HC595 schematic

Step 4: Solder LEDs to Sparkfun PCB

Thread the leads of 16 LEDs (5mm or 3mm are fine, I used 5mm) through LED holes in the sparkfun PCB.  These boards are compatible with 4 lead RGB LEDs, so there are four available holes on each button pad.  You can use the two center holes for single color LEDs (see figure 3).  Be sure that the flat edge of the LED (the cathode) lines up with the flat marking on the PCB.

Solder the LED leads and cut away the excess wire.

If you do not have a sparkfun PCB:
See figures 7 and 8 for the LED matrix wiring diagram.  Connect the anodes (long lead) of each row of LEDs together and the cathodes (shorter leads) of each column of LEDs together in the matrix.

 

For more detail: Multiplexing with Arduino and the 74HC595


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top