Instructables

Multiplexing with Arduino and the 74HC595

Featured
Picture of Multiplexing with Arduino and the 74HC595
FKCG4RPH1ZG7675.jpg
led matrix_schem.jpg
labeled schem.jpg
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 4x4 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 4x4 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 4x4 - LED Compatible Sparkfun COM-07835
(1x) Button Pad 4x4 - 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
 
Remove these adsRemove these ads by Signing Up

Great project! I've been messing with this myself. Were you able to get a RGB led working with this board?

amandaghassaei (author)  cookieman45918 days ago

haven't tried yet, should be no problem if you copy this circuit 3x

The issue I have had is with the matrix being based on ground. When I tried this X3 it caused all sorts of weirdness since the ground connection (I think) created a lot of closed circuits that shouldn't be closed. Basically lots of extra lights and colors. I couldn't get any isolation like X1 worked.

It's also quite possible I just did something stupid. Possibly I need some more diodes in the design to prevent some crossflow.

bondike1 month ago

And how does that work with PWM "data"? Can registers "remember" the pulse width?

amandaghassaei (author)  bondike29 days ago

you can't do pwn output with a 74HC595, check out the tlc5940 instead

I would like to point out to the entire universe that what everyone is calling multiplexing is in reality DE-Multiplexing.

I don't know how or when it all got confused, but everyone is doing it now, and it kinds bugs me!

Multiplexing is when you take a large number if signals, and combine them into a few lines. A good example of this is when 500 apartments in an apartment building all have their telephone lines connected by one fibre optic line to the phone company. De-multiplexing happens when the fibre optic line comes back to the apartment and then becomes 500 individual phone lines. So what we are really doing with our microcontrollers sending out data that gets spread across a much larger number of devices or wires (LEDs usually) is de-multiplexing. If we were to take 250 push-buttons and connect them all to the Arduino with 2 wires so that it could tell which button was pressed, that would be multiplexing.

That said - Nice project!

zmarotta4 months ago
Awesome! Any idea how I can do this with 100 RGB LEDs? :)
abhijitkooool5 months ago
//LED TEST 2 w/ 74HC595
//by Amanda Ghassaei 2012
//http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

//this code will display the values of ledData across a 4x4 led matrix

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

//storage for led states, 4 bytes
byte ledData[] = {1, 3, 7, 15};

void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

for (i=0;i<4;i++){

//send data from ledData to each row, one at a time
byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);

// setlatch pin low so the LEDs don't change while sending in bits
digitalWrite(latchPin, LOW);
// shift out the bits of dataToSend to the 74HC595
shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);

}
}

//LED TEST 2 w/ 74HC595
//by Amanda Ghassaei 2012
//http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

//this code sends data to the 74HC595 without "shiftOut"

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin A1
#define clockPin A0
#define dataPin A2

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend;

//storage for led states, 4 bytes
byte ledData[] = {1, 3, 7, 15};

void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

for (i=0;i<4;i++){

//send data from ledData to each row, one at a time
byte dataToSend = (1 << (i+4)) | (15 & ~ledData[i]);

// setlatch pin low so the LEDs don't change while sending in bits
digitalWrite(latchPin, LOW);

// // shift out the bits of dataToSend to the 74HC595
// shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
// the code below is the equivalent of the two lines above
for (j=0;j<8;j++){
digitalWrite(clockPin,LOW);
digitalWrite(dataPin,((dataToSend>>j)&1));
digitalWrite(clockPin,HIGH);
}


//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);

}
}
sanjoseph8 months ago
arabic letters!!! do u have any idea if is there any software used with arduino to blink led screen????
sanjoseph8 months ago
thanx dear for answer...
because i am new to work with arduino...
i have some problems about alphabet [][] function cuase i dont know how does work and how it generate litters and how can i generate latin words by using ascii???
best regards....
amandaghassaei (author)  sanjoseph8 months ago
what letters do you want to make?
amplex8 months ago
I'm guessing we could use 3 74HC595 circuits with an arduino to control RGB LED's that this board was intended for use with? If we had 9 analog pins on an standard arduino that is. If we could use the same clock pin for all 3, that would cut down the pins to 7. It looks like a Mega would be the only way to make this happen.
sanjoseph9 months ago
dear sir...
u have explained 4*4 led matrix connected to arduino..
but i dont have any idea how to connect 8*8 leds using 74hc595 to arduino???any help plz
amandaghassaei (author)  sanjoseph9 months ago
same idea, but you need two 74hc595 - one connects to the 8 rows and the other to the eight columns.
ignatiusD1 year ago
Hi, I've been reading about muxing and things, and the title of this instructable is kind of confusing to me because if I'm not mistaken you're using a shift register, not a multiplexer. Is there not a significant difference?
amandaghassaei (author)  ignatiusD1 year ago
the terminology is kind of ambiguous, a shift register implies something digital, like the chip I'm using. Multiplexing in general is this technique of controlling an array, a multiplexor is something that does the multiplexing. often people refer to analog chips as mux/demux and digital as shift registers, but they both do multiplexing.
TAGAPAW1 year ago
Hi It's really Nice Instructables, but can this method to light up up to 120 button simultaneously , thank you very much
amandaghassaei (author)  TAGAPAW1 year ago
yes, definitely.
Great Instructable!
One this I am a bit confused about. What is you want to light more than one LED at once.
Wouldn't this cause some other lights to illuminate unexpectedly using this method?
amandaghassaei (author)  Fuzzy-Wobble1 year ago
no you can control exactly which leds you want to light. In step 13 I show how you can address each led in the matrix. You can light up many at the same time with no problem.
could ya make a video of the finished project
amandaghassaei (author)  francisroan1 year ago
I will, but I'm still working on it. it's going to be a fancier version of this.
Jayefuu1 year ago
Nice work! This is very complete :)
amandaghassaei (author)  Jayefuu1 year ago
thanks!
Favourited, I just happen to have a large bag of LEDs and a bunch of 595s.
megaduty1 year ago
Fave'd this and will be using later in a project; thanks for the ible!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!