Skip to main content

How to use a Shift Register 74HC595





Shift Register


Introduction 


In this tutorial you will learn how to use a shift register (or serial to paralled controller). The shift register will give to your Arduino an additional 8 digital outputs, by using only 3 pins on your board
In this tutorial you will practice by using the shift register with Arduino uno to control 8 LEDs.

Picture

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • Shift Register IC (74HC595)
  • 4x Red LEDs
  • 4x Green LEDs
  • 8x 330 Ohm (or 220) resistors
Picture

The Circuit

Picture
Picture
The connections are easy, see the image above with the breadboard circuit schematic.


You can find more info about IC here: datasheet
Picture
Here's the code!
We will use example sketch from ShiftRegister74HC595.h library.
How it works:
  • sr.setAllHight(); Turn all LEDs on
  • sr.setAllLow(); Turn all LEDs off
  • sr.set(i, HIGH); Turn LED i on ( 0 < i < 7)
  • uint8_t pinValues[] = { B10101010 }; 
  • sr.setAll(pinValues); Binary to turn on 2nd,4th,6th and 8th LED
The Code ::
********************************************************************************

/*
  ShiftRegister74HC595.h - Library for easy control of the 74HC595 shift register.
*/

#include <ShiftRegister74HC595.h>

// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (1, 2, 3, 4); 
void setup() { 
}

void loop() {
  sr.setAllHigh(); // set all pins HIGH
  delay(500);
  sr.setAllLow(); // set all pins LOW
  delay(500); 
  for (int i = 0; i < 8; i++) {
    sr.set(i, HIGH); // set single pin HIGH
    delay(2000); 
  }
    // set all pins at once
  uint8_t pinValues[] = { B10101010 }; 
  sr.setAll(pinValues); 
  delay(5000);
  // read pin (zero based)
  uint8_t stateOfPin5 = sr.get(5);
  
}
********************************************************************************

Note :: Try to change line: 
uint8_t pinValues[] = { B10101010 }; with uint8_t pinValues[] = { B11001100 };

Well done!

Picture
You have successfully completed one more "How to" tutorial and you learned how to use a shift register ic with Arduino. I hope you liked this, let me know in the comments. You can also post photos with your circuit!



Comments

Post a Comment

Popular posts from this blog

Build Your Own Arduino Weather Station

Arduino ​Obstacle Avoiding Robot Ardunio Computer

Complete Guide for Nokia 5110 LCD with Arduino