3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

8 LED Chaser with 74HC595 8 Bit Shift Register

8 LED Chaser with 74HC595 8 Bit Shift Register
Have you wanted to make a sweet Cylon/Knight Rider (Larson) Scanner effect? But you don’t want to use up all of your Arduino IO pins? Well, you can make a nice 8 LED Scanner with a shift register IC.

In this tutorial we’ll be using the 74HC595 8 Bit Shift Register, and this is what we'll be making;



Parts Required:
Arduino Uno (Or Arduino compatible clone)
Jumper Wires (Various colours and lengths)
1x 74HC595 8 Bit Shift Register
1x Breadboard
8x 220 Ohm Resisters
 
Remove these adsRemove these ads by Signing Up
 

Step 1Get Ready to Shift

Get Ready to Shift
«
  • 02.JPG
  • 03.JPG
  • 04.JPG
  • 595_pin_diagram.png
Take your shift register and place it on your breadboard over the IC gap, now take your black jumper wires and you’ll want to ground the IC, taking note where the notch is (Pin 1 is usually left of the notch) you’ll want to ground pin 8 and pin 13.
« Previous StepDownload PDFView All StepsNext Step »
23 comments
Apr 12, 2012. 5:43 AMrobot797 says:
can somone give me the code for 2 595 shifters
i am gonna rewrite it so you can use it with only 2 wires
Apr 27, 2012. 4:16 PMBaron von Biffo says:
Hi Robot797,

The following code works with two 595s. Be sure to connect the overflow pin of the first 595 to the data in pin of the second and connect the clock and latch pins together.

HTH,

von Biffo.


/*

A simple 16 LED chaser using two 74HC595N serial in/parallel out shift registers.
This sketch causes one of sixteen LEDs to be lit in turn moving up and down the display.

By Baron von Biffo

28th April 2012.

*/


// setup the data, latch and clock pins for the 74HC595.

int dataPin = 2;
int latchPin = 3;
int clockPin = 4;

void setup(){

// Set the data, latch and clock pins to output mode.

pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);

}

void loop(){

// Setup array with the individual LED positions. Decimal is easier to use than binary.
unsigned int displayLED[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};

// Setup two 8 bit bytes to hold the data for each 595.
uint8_t low_byte;
uint8_t high_byte;

// Set length of time to display each LED.
int pause = 45;

// Loop control variable
int count;


// Count up loop.
for(count = 1; count < 16; count++){

// Read the decimal value from the array. Use bitwise And with OxFF for the low byte
// and shift 8 bits right for the high byte.
//
// I learned this from Korman at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285651171
//

low_byte = displayLED[count] & 0xff;
high_byte = (displayLED[count] >> 8);

// set the latch pin low prior to shifting out the data.
digitalWrite(latchPin, LOW);

// Shift out the data. The first shiftout puts the high byte into the first 595.
// The second shiftout shifts the high byte from the first 595 to the second and
// shifts the low byte into the first 595.
shiftOut(dataPin, clockPin, MSBFIRST, high_byte);
shiftOut(dataPin, clockPin, MSBFIRST, low_byte);

// Display the data by setting the latch pin high.
digitalWrite(latchPin, HIGH);

// Pause for the number of miliseconds determined by the 'pause' variable.
delay(pause);

}

//Count down loop. Same as the count up loop but moves in the opposite direction.
for(count = 16; count > 0; count--){

low_byte = displayLED[count] & 0xff;
high_byte = (displayLED[count] >> 8);

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, MSBFIRST, high_byte);
shiftOut(dataPin, clockPin, MSBFIRST, low_byte);

digitalWrite(latchPin, HIGH);
delay(pause);

}
}
Jan 30, 2012. 2:53 AMschool grants for women says:
I think I understand what you mean - the '595 will take the school grants for women first 8 bits for itself and then pass on anything more. The next '595 does the same, and so on. The data gets 8 bits shorter each time until it runs out of bits.
Oct 20, 2011. 3:43 PMUgifer says:
Looks great! You could create some stunning effects with a few of these, or even make an LED matrix display!

I guess you don't need a separate latch pin for each chip so in effect you seem to be getting 8 outputs for every pair of normal pins, with 1 extra pin for latching. That's potentially a lot of outputs!
Oct 21, 2011. 6:44 AMUgifer says:
Thanks for your response - That's fantastic.

Only question - how do you know which '595 you are writing to? Maybe it's clear from the code but I missed that if so.

It occurs to me that a shift register has just the right number of outputs to control a seven-segment+decimal LED display.... wouldn't take a whole lot of code to write a library that would output any number of digits to daisy-chained 7-segment displays with a shift register attached to each.

I may have to try that.
Oct 21, 2011. 8:32 AMUgifer says:
Great! I think I understand what you mean - the '595 will take the first 8 bits for itself and then pass on anything more. The next '595 does the same, and so on. The data gets 8 bits shorter each time until it runs out of bits.

There probably is a library for this but I'm just starting out with micro-controllers (you might have guessed) so I might just make it a project anyway.....

Thanks for all your help.
Jan 22, 2012. 9:37 AMjborgne says:
actually the first shift reg will use the last 8 bits shifted before latch.
i dont think you can send 16 bits at once either. eg B1111111111111111
due to the arduino language not having a consistent defined for anything over 8 bit. (This may have changed for the 1.0 IDE)

if i had 2 shift's i would send like so


shiftout(reg2);
shiftout(reg1);
digitalWrite(latchPin, HIGH);


note this is not working code just to show how it works.

3 shifts? just add the last shift first like so

shiftout(reg3);
shiftout(reg2);
shiftout(reg1);
digitalWrite(latchPin, HIGH);


HTH,
Jan 23, 2012. 1:34 AMUgifer says:
You are quite right - since seeing this I have now constructed a little greenhouse thermometer and relay heater control that uses 3 x '595s and 7-segment displays to show current, ave, max & min temperatures in my little greenhouse and switch in a small heater when it gets too low.

I used exactly that type of code and it works great. When I have a minute I'll write it up as an 'ibble.

There is a ShiftOut tutorial on the arduino site that's very helpful for these things.
Nov 24, 2011. 1:46 PMjborgne says:
i was wondering how everyone sent a binary pattern to the function.
I was sending 00000011 instead of B00000011.
I ended up converting the binary to base-10 and sending that.
After reading this instruct I see i needed to add a B to the binary.


thanks
Oct 19, 2011. 3:40 PMlesic25 says:
Very well, good idea, it is pleasant to know that there are such creative people
Oct 20, 2011. 2:16 PMEax5 says:
Great Instrucable,

I just finished learning about these from a different source and making a Connect 4 clone.

Just some advice, if any one having issues if LEDs flickering when they are not supposed to you might want to add a .1uF capacitor between the Vcc(pin 16) and ground.

I need to figure something out to do with the extra 7 chips I have lying around
Oct 20, 2011. 4:41 PMsgovani says:
u could just individually connect each pin of the led graph to aio pin and the negative pin to ground, then just set the connected pins to ether high or low, with a delay in middle
Oct 19, 2011. 5:30 PMmatt.e.jenkins says:
Great job, I have some of those chips laying around. I'll give it a try. I had the idea of making my son a toy robot and making its mouth a Larson scanner. With the shift register I can use a attiny and save money. Good One.
Oct 19, 2011. 9:14 AMRobot Lover says:
I like it! Good job of narrowing it down to as few pins as possible! This could be used for other stuff as well. Good ible! Totally worth 5*
Oct 19, 2011. 10:35 AMRobot Lover says:
Yeah. These are what they use in arduino I/O expander shields.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
24
Followers
6
Author:Dominion-Network(Dominion-Network)
I've always taken stuff apart, almost always put it back together... I enjoy tinkering around with pretty much anything.