Introduction: 74HC595 Shift Register

About: Electrical Engineer, control systems, automation, small electronics, home automation, microcontrollers etc.

This will be a quick start guide to the 74HC595 Shift register.  

The shift register operates in a fairly simple way, but can be modified to become very complicated but very useful.

The basic concept is you have 8 output pins from the 74HC595.  For this example lets just say these are sent through a resistor to an LED.  So we have pins Q0 through Q7 as the output pins.  The rest can be considered control pins, their exact function is outlines in the table above. 

We can control the shift of the register with clock pulses.  As we raise the signal going to the clock pin to high, the clock is moved forward one step.  and when we pull it low and high again it shifts another.  Each time we shift the clock we switch the input to a different one of the eight registers.  We are essentially controlling the output of each of the eight pins one at a time, and as we move one clock signal forward, we switch to the next output pin to control.  

So far this simply sounds like a switch board, which is really what it is, but here's the key.

We can use the Storage register clock pin to control the "Master On/Off" switch.  Essentially how this is used is we can pull it low before we send our register values.  We then send all eight register values, whether they be high or low, and when we are done we pull the Storage register clock pin high.  What will happen is the value you send will be stored on each output pin, but not activated yet.  When you pull the storage register clock pin high all the outputs will then become active, and which ever pins you assigned as high will illuminate the LED.

Another perk is the Master Reclear Pin.  We can use this pin to clear all of our outputs and set everything to low.

So this is just a simple example.  The shift register can be a great tool when you are short on output pins, taking 8 outputs from only about 3 actual data inputs.  It can be added to for some really complicated applications, and they can be daisy-chained together for even more output options.

Hopefully this will help get you started and give you some knowledge on their basic concept.

I have included a sample arduino sketch and the wiring diagram from the arduino website that will turn on each LED one at a time given Serial Monitor input (0-9)


-------------------------------------- CODE START --------------------------------------
/*
  Shift Register Example
for 74HC595 shift register

This sketch turns reads serial input and uses it to set the pins
of a 74HC595 shift register.

Hardware:
* 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino,
as detailed below.
* LEDs attached to each of the outputs of the shift register

Created 22 May 2009
Created 23 Mar 2010
by Tom Igoe

*/

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("reset");
}

void loop() {
  if (Serial.available() > 0) {
    // ASCII '0' through '9' characters are
    // represented by the values 48 through 57.
    // so if the user types a number from 0 through 9 in ASCII,
    // you can subtract 48 to get the actual value:
    int bitToSet = Serial.read() - 48;

  // write to the shift register with the correct bit set high:
    registerWrite(bitToSet, HIGH);
  }
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
// the bits you want to send
  byte bitsToSend = 0;

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

}
--------------------------------------- CODE END ---------------------------------------

I will try to get back to this to add more explanation to this code.