Rachana Jain
Published © GPL3+

74HC595 Shift Register with Arduino UNO

In this tutorial you will explore the working of the 74HC595 shift register and interface it with an Arduino.

BeginnerFull instructions provided2 hours203

Things used in this project

Hardware components

Arduino Uno R3
×1
74HC595 shift register
×1
LED (generic)
LED (generic)
×8
Resistor 220 ohm
Resistor 220 ohm
×8
connecting wires
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Arduino Code for Interfacing 74HC595 Shift Register with Arduino

Arduino
/* 
Code to interface 74HC595 SIPO shift register using Arduino UNO
by www.playwithcircuit.com
*/
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
//Pin connected to DS of 74HC595
int dataPin = 11;
//Pin connected to ST_CP of 74HC595
int latchPin = 10;
//Pin connected to OE of 74HC595     
int brightnessPin = 9;
//Brightness control variable
int PWM_Value = 0;
void setup() {
  //set pins to output so you can control the shift register  and initially they should be HIGH
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(brightnessPin, OUTPUT);
  digitalWrite(latchPin, HIGH);
  digitalWrite(clockPin, HIGH);
  digitalWrite(dataPin, HIGH);
  analogWrite(brightnessPin, 255);
}
void loop() {
  int led_byte = 0x00;
  //  turn ON all LEDs one by one 
  for (int i = 0; i < 8; i++) {
    // adjust the brightness of LEDs
    PWM_Value = (255 - (115 + (20*i)));
    analogWrite(brightnessPin, PWM_Value);
    led_byte |= (0x01 << i);
    // take the latchPin low
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, led_byte);
    //take the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value:
    delay(100);
  }
  //  turn OFF all LEDs one by one 
  for (int i = 0; i < 8; i++) {
    led_byte &= ~(0x01 << i);
    // make the latchPin low
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, led_byte);
    //make the latch pin high so the LEDs will light up:
    digitalWrite(latchPin, HIGH);
    // pause before next value
    delay(100);
  }
}

Credits

Rachana Jain
17 projects • 11 followers
I'm an avid Arduino and electronics enthusiast with a passion for tinkering, experimenting, and bringing innovative ideas to life.

Comments