Multiplexing with Arduino and the 74HC595
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:
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
Step 1: What Is Multiplexing?
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 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
Arduino Pin Connections to 74HC595
A0 Clock Pin (pin 11)
A1 Latch Pin (pin 12)
A2 Data Pin (pin 14)
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
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days
This Post / Project can also be found using search terms:
- 74hc595 دیتاشیت