Arduino

How to Use 74HC595 Shift Register with Arduino

All the Arduino boards come with a specified number of I/O pins and if there are a large number of devices that are to be connected with the Arduino board the problem of shortage of pins might arise. To cater this issue there are shift registers through which we can increase the number of I/O pins of the Arduino. How these shift registers work and how we can use them with Arduino, let’s find out:

How Shift Registers Work

As described above the shift register is mainly used to resolve the pin shortage of microcontroller in case when a large number of devices are to be interfaced with the microcontroller. The shift register shifts the data from one bit to another with respect to the pulses of the clock of the register and the data it shifts is stored in it. There are three main pins of the shift register: one is the clock pin , second is latch pin and third is the data pin.

The pin configuration of a single shift register (74HC595) is given below in the table:

Pins category (From Left side of grove) Pin Numbers Representation Description
Output pins  1-7 and 15 Q1 to Q7, Q0 Pins at which the device is to be interfaced with controller
Power pins  8 and 16 GND, VCC Pins which will power up the shift register
Serial input  14 (DS)SERIN Pin which receives the data from the controller through serial communication
Output Enable  13 OE This pin is LOW when voltage is HIGH and vice versa
Latch pin 12 (ST_CP)RCLK When this pin is HIGH the data is sent to the output pins and is also stored in the memory
clock pin 11 (SH_CP) Clock pin for the shift register
RESET pin 10 (SH_CP)SRCLR Pin use to reset the register by giving it LOW state
Interfacing of other registers  9 Q7s (QH’) When more than one registers are to be used, this pin is used

Using shift register with Arduino

To explain how we can use the shift register with Arduino we have demonstrated an example of connecting multiple LEDs with Arduino Uno through a shift register. Here is the list of components that we have used in this example:

  • Breadboard
  • Connecting wires 
  • 8 LEDs 
  • Arduino Uno
  • 74HC595 Shift Register

We have designed the circuit using the above listed components and its schematic is given below:

Hardware assembly for using shift register with Arduino Uno

To see how the circuit will look like on the breadboard we have first made the hardware assembly as in the image below:

For your understanding we have explained the connections of the components used in the circuits:

  • The purple wire shows the data pin connection of the shift register with Arduino using its pin 4.
  • The white wire represents the connection for the latch pin with Arduino Uno that is connected to its pin 5 whereas the brown wire is used to connect the clock of the shift register with Arduino using its pin 6.
  • To connect the LEDs with the shift register we have used the gray wires and the grounding of the LEDs is done by using the black wires.
  • For connecting the shift register with supply we have used the 5-volt option of the Arduino from  its power supply pins.

Arduino code for using shift register with Arduino Uno

To use shift register with Arduino we have to configure it by programming the microcontroller so below we have provided the code:

int latch = 5;// pins 5 of Arduino for Latch pin of shift register
int clock = 6;// pins 6 of Arduino for clock pin of shift register 
int data = 4;   // pins 4 of Arduino for data pin of shift register

byte led = 0;       // Variable which will save the value of LEDs

void setup()
{
// assigning the working modes to the pins of shift register
  pinMode(latch, OUTPUT);
  pinMode(data, OUTPUT);  
  pinMode(clock, OUTPUT);
}

void loop()
{
  led = 0;// at the start all the LEDs will remain in off state
  ShiftRegister(); // turn on the  next LED
  delay(500);
  for (int i = 0; i < 8; i++)   // loop that will turn the LED one by one
  {
    bitSet(led, i); // assigning the respective LED the HIGH values
    ShiftRegister();// turn off the previous LED
    delay(500);
  }
 
}
// function that will update the register after each iteration of for loop
void ShiftRegister()
{
   digitalWrite(latch, LOW);
   shiftOut(data, clock, LSBFIRST, led);
   digitalWrite(latch, HIGH);
}

Hardware Demonstration

We have implemented the circuit designed for interfacing the 74HC595 shift register with Arduino Uno according to the hardware assembly that we have described earlier. To demonstrate how we have turn the LEDs in a pattern we have given the animated Gif below:

Conclusion

Shift registers are used mostly when we have to increase the I/O pins of the microcontrollers so that we can interface more devices with it. To demonstrate how we can use the shift register we interface 8 LEDs with the Arduino microcontroller by only using its 3 pins. For further clarification we have given circuit schematic and its implementation of hardware along with the Arduino sketch used to program the controller.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.