How does 74hc595 shift register work | Step by step instructions

Hello, welcome back. In this tutorial, I will show you how the 74HC595 shift register works with an Arduino. This tutorial is particularly useful if you want to control many outputs using just three pins on an Arduino or another microcontroller. We’ll use an Arduino to demonstrate this, with 8 LEDs connected to a single shift register. By using this shift register, you can control all 8 LEDs with only three digital pins. You can chain multiple shift registers together if you need more outputs, but you will still only need three pins to control them. This technique can also be applied to create projects like LED matrices or LED cubes.

What is the 74HC595 Shift register IC and how does it work?

That is simply called 8-bit shift register IC. That is, it contains 8 bits of memory. These eight bits remain as “0” before a pulse is given.

How does 74hc595 shift register work

We mainly need the following 3 pins to work with this shift register ic. These are included in the shift register IC itself.

  • RCLK – Register clock
  • SRCLK – Serial clock
  • SER – Serial

The first step is to set the three control pins to HIGH. Next, set the register clock to LOW to initiate serial communication and prepare the shift register. Then, set the serial clock to LOW. This action shifts the values of the eight outputs one position forward in the register. Essentially, the value in the first position moves to the second position, while the value in the last position is discarded. If additional shift registers are connected, the process will continue with the next shift register. As a result, the first output will be cleared.

How does 74hc595 shift register work

You can set a value for this empty pointer. It should be 0 (low) or 1 (high). For this, the serial pin can be HIGH or LOW. That means if we make the Serial pin HIGH, the value of that index will be written as 1.

How does 74hc595 shift register work

Now we need to HIGH the register clock pin again to get an output from the pin corresponding to this index. That is, to light the LED bulb connected to that pin. Then the first LED bulb lights up. Continuing this process will cause the LEDs to light up one by one.

PIN structure of this 74HC595 shift register

  • Q0 to Q7 — Output PINs.
  • GND — connect to the  Arduino GND.
  • VCC — Connect to the VIN or 5v.
  • SER — Data sending pin.
  • OE — When this pin is HIGH, the output pins are disabled, and current flow is prevented. Also, when this pin is low, the output pins work normally.
  • RCLK — Register clock PIN (Described above)
  • SRCLK — Serial clock (Described above)
  • SRCLR — This pin is used to reset the memory in the shift register.
  • Q7` — This pin is used to connect another shift register

So, let’s learn how to connect this 74HC595 shift register step by step with Arduino. To do this, the required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. For that, use the circuit diagram below.

How does 74hc595 shift register work with arduino

Step 3

Thirdly, let’s create the program for this tutorial. It is as follows.

  • 74HC595 library — Download
  • The complete program of this project – Download
/*How to use 74hc595 shiftRegister.
  Four LED patterns.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creations.
*/
 
#include <ShiftRegister74HC595.h>//include library
ShiftRegister74HC595<1> led(4, 2, 3);//<number of shiftregisters>object name(data pin,clock pin,latch pin)
 
void setup() {
}
 
void loop() {
  pattern1(2);
  pattern2(2);
  pattern3(2);
  pattern4(2);
}
 
void pattern1(int a) {
  for (int x = 0; x < a; x++) {
    led.setAllHigh();
    delay(300);
    led.setAllLow();
    delay(300);
  }
}
void pattern2(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, HIGH);
      delay(100);
      led.set(a, LOW);
    }
    for (int b = 7; b > 0; b--) {
      led.set(b, HIGH);
      delay(100);
      led.set(b, LOW);
    }
  }
}
void pattern3(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, HIGH);
      delay(100);
    }
    for (int b = 7; b > 0; b--) {
      led.set(b, LOW);
      delay(100);
    }
  }
}
void pattern4(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, LOW);
      delay(100);
      led.set(a, HIGH);
    }
    for (int b = 7; b > 0; b--) {
      led.set(b, LOW);
      delay(100);
      led.set(b, HIGH);
    }
  }
}

Code explanation

First, the shift register library is included.

#include <ShiftRegister74HC595.h>

Then, the object was created for the library. It includes shift register quantity and data pins. For that, use the below structure.

<number of shiftregisters>object name(SER,SRCLK,RCLK)
 
ShiftRegister74HC595<1> led(4, 2, 3);

In the setup function, nothing is included.

void setup() {
}

In the loop function, four LED patterns are called. If you want to run these LED patterns one by one, comment on patterns other than the required pattern.

void loop() {
  pattern1(2);
  pattern2(2);
  pattern3(2);
  pattern4(2);
 
}

These pattern codes are as follows.

void pattern1(int a) {
  for (int x = 0; x < a; x++) {
    led.setAllHigh();
    delay(300);
    led.setAllLow();
    delay(300);
  }
}
void pattern2(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, HIGH);
      delay(100);
      led.set(a, LOW);
    }
    for (int b = 7; b > 0; b–) {
      led.set(b, HIGH);
      delay(100);
      led.set(b, LOW);
    }
  }
}
void pattern3(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, HIGH);
      delay(100);
    }
    for (int b = 7; b > 0; b–) {
      led.set(b, LOW);
      delay(100);
    }
  }
}
void pattern4(int a) {
  for (int x = 0; x < a; x++) {
    for (int a = 0; a < 8; a++) {
      led.set(a, LOW);
      delay(100);
      led.set(a, HIGH);
    }
    for (int b = 7; b > 0; b–) {
      led.set(b, LOW);
      delay(100);
      led.set(b, HIGH);
    }
  }
}

Step 4

OK, now select board and port, Afterward, upload this code to the Arduino board.

OK, enjoy this tutorial. The full video guide is given below. So, we will meet in the next tutorial. Have a goo day.

How does 74hc595 shift register work | Step by step instructions

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *