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
Nighter3D17 days ago

Ugh...this IC has caused far more Headache then any other T_T

The thing is that the Chip itself is rated to a maximum current of 70ma in total, meaning that to drive more then a few Leds or such at a time is suicidal...And yet in Practice the chip seems to hardly break a sweat. this has resulted in a fissure between people saying it CAN and others that keep yelling it will Burn.

Personally Ive come up with the theory that people should take the datasheet with a grain of salt. It says 70ma in current perhaps, but it never specified if its the actual same voltage which in the end together with the current defines the actual Power in Watt being drained/sourced. Heck i have one right besides me that seems able to Drive a Numitron tube that draws 20ma at 3.3v with ease!

Great IC...although better clarity at its maximum should be looked into by the manufacturers...or whoever designed the first one of which all manufacturers have copied the design off.

SuperTech-IT4 months ago

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!

I too, like to use the correct terms when explaining, and I understand your frustration, but this instructable is geared more for beginners, so "multiplexing" makes it easier to understand.

Actually it is neither multiplexing or demultiplexing. You could consider it a DEMUX because it is a serial to parallel conversion, but each output is staggered based on the clock (so it is 8 in 8 out --kinda/sorta), which doesn't occur using MUX or DEMUX. The best term I can come up with is "Serial In to Parallel Out Shifted", which is awkward and wordy. Because it appears to multiply the output (persistence of vision), multiplexing is a (wrong) but better explanation.

Serial to parallel conversion is the most common form of demultiplexing.

The outputs do not have to be simultaneously active and actually rarely are.

Take the 74HC138 or 74HC238 which based on a binary number, demultiplex the single bit input to one of it's 8 outputs. Only one of the 8 outputs is ever active at once by design, and it is a demultiplexer. You can send 10,000 bits to output 1, and then send 10 bits to output 5 and then send 2 bits to output 6 - but it's still demultiplexing by definition.

Since I no longer am employed in electronics, I don't know enough to give you a good argument. My last formal schooling was building 555 timer circuits using transistors, caps, etc.; logic gates from diodes. :) Troubleshooting tube based radios. (Anybody know about the ARC51 and tuning using sharpened wooden rods?) Fun Fun. (Navy Schools). Now it just a hobby, after leaving the Corps in '97.

Now I am on the software side of IT. (DOTNET rules!) Not to impose on Linux followers, I have a UBUNTU stick whenever I want to experiment, and I first started programming using LAMP.

Those two chips you referenced look to me that they are all composed of logic gates. Some outputs look staggered, but I don't see a clock signal. Is this delay intentional, or just a side affect?

I don't know what you mean by delay - the only delay these chips might have is the tiny insignificant amount of propagation delay between input and output - otherwise it's pretty much instantaneous. The chips I mentioned have no clock. There are 2 inverted enable lines, 1 non-inverted enable line, any of which could be considered the "data" being presented at the output. If the inverted enables are grounded, and the other enable is at +v, then a "1" will be at whatever address is presented to the 3 address bits.

Yes, if you wanted to, you can break just about anything down into discrete gates, and if you did that with this chip, it would look like this for the 74HC238 (invert the outputs for the 138).

74XX238 logic.jpg

If you wanted this chip to distribute data evenly across the 8 outputs with respect to a clock, then all you'd have to do is connect the non inverted enable to your "data" bit, and put the clock into a counter like a 74HC393 and use 3 bits of the counter's output as the address bits going into the 238's address lines. Since the 2 counters in the 393 are 4 bits, we would simply tie the 4th bit of the counter we are using to the reset line so that it becomes a 3 bit counter. VOILA, multiplexed serial in to 8 demultiplexed serial out.

Thanks for the clarification, but if I had to explain the difference to my wife, it would go right over her head and simplify via this Instructable.. :)

As far as the ARC-51 goes, I never thought about Googling it, as all of our pubs (at the time) were classified material. Maybe since they have been phased out you can now download the schematics.

http://members.home.nl/a.k.bouwknegt/index_bestand I wish I had that resource back in the 80's instead of digging through 5 inch binders. :) Kinda cool. Now if I can find that power supply schematic for an APX100 (IFF) that supplied 2000VDC (my guess but I know it was over a thousand volts) from aircraft power. I still have a scar from that little bugger, it was smaller than an ATX PS. Burned a hole right through my palm. If you can find it, it had one card that was composed entirely of diode gates.

Again, thanks for taking the time to reply and clarify!

It would have been diodes and capacitors, because what you are describing is a simple voltage multiplier. A scaled down schematic is here...

Voltage Multiplier.jpg

Finally found the original manual that I used daily. I can't upload it because it is over 800 pages. I downloaded it, closed my browser, but now I can't get back in. But if you go to http://www.liberatedmanuals.com and do a search for NAVAIR 16-30APX72-2 it should let you view it. That site limits the amounts of downloads/day. Here is a functional diagram and a schematic (sorry a bit fuzzy).

APX100PS_FuncDiag.pngAPX100PS.png

Well, I think we have strayed far enough off topic on this poor man's thread.

This started out as multiplexing VS demultiplexing, so I think I am just going to terminate our personal sideline here. If you wish to keep discussing things like this, then you can inbox me or post on my orangeboard.

I need to get back to work on my RGB LED cube PC boards anyways.

As an aside, I don't think many here have ever seen an ARC51 tranceiver.

cookieman4594 months ago

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

amandaghassaei (author)  cookieman4594 months 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.

bondike4 months ago

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

amandaghassaei (author)  bondike4 months ago

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

zmarotta7 months ago
Awesome! Any idea how I can do this with 100 RGB LEDs? :)
abhijitkooool9 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);

}
}
sanjoseph12 months ago
arabic letters!!! do u have any idea if is there any software used with arduino to blink led screen????
sanjoseph1 year 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)  sanjoseph1 year ago
what letters do you want to make?
amplex1 year 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.
sanjoseph1 year 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)  sanjoseph1 year 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.
francisroan2 years ago
could ya make a video of the finished project
amandaghassaei (author)  francisroan2 years ago
I will, but I'm still working on it. it's going to be a fancier version of this.
Jayefuu2 years ago
Nice work! This is very complete :)
amandaghassaei (author)  Jayefuu2 years ago
thanks!
Favourited, I just happen to have a large bag of LEDs and a bunch of 595s.
megaduty2 years ago
Fave'd this and will be using later in a project; thanks for the ible!