shift registers

Shift Registers Arduino Tutorial – Expanding Arduino Outputs

Using shift registers with your next Arduino project will allow you to drive multiple outputs with less pins. The 74HC595 IC is extremely versatile; it can be used to drive LEDs, motors and even Servos.

Shift Register Pinout

The shift register pin out is quite simple; refer to the table below to make your connections.
shift register pinout

Shifting eight outputs

You will need to make the connections described below. You may use different loads than the LEDs displayed and other outputs on the Arduino board. Make sure to change the configuration in the software if you decide to do so.
shift register wiring connection

The code to start shifting!

The software is quite simple. You will need to create a register of 8 bits and shift it in when you want to update the actual register. The sample code blow illustrates a simple example which you can copy and paste into your project.

///////////////////////////////////
int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;
void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
}
boolean registers[8];
void writereg()
{
digitalWrite(STCP_pin, LOW);
for (int i = 7; i>=0; i--)
{
digitalWrite(SHCP_pin, LOW);
digitalWrite(DS_pin, registers[i] );
digitalWrite(SHCP_pin, HIGH);
}
digitalWrite(STCP_pin, HIGH);
}
void loop()
{
for(int i = 0; i<8; i++) { registers[i] = HIGH; delay(100); writereg(); } for(int i = 7; i>0; i--)
{
registers[i] = LOW;
delay(100);
writereg();
}
}
///////////////////////////////////

Multiple Shift Registers from three pins

It is possible to chain shift registers in order to use any multiple of outputs with the same three pins. You simply need to connect the output of the first shift register to the input of the next one and make sure the clock signals are also sent along. Here is the schematic you can use as an example as well as the small code modifications you will need to run two shift registers at once.
chained shift registers

The following code is used for two shift registers or a total of 16 outputs.

///////////////////////////////////
int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;
void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
}
boolean registers[16];
void writereg()
{
digitalWrite(STCP_pin, LOW);
for (int i = 15; i>=0; i--)
{
digitalWrite(SHCP_pin, LOW);
digitalWrite(DS_pin, registers[i] );
digitalWrite(SHCP_pin, HIGH);
}
digitalWrite(STCP_pin, HIGH);
}
void loop()
{
for(int i = 0; i<16; i++) { registers[i] = HIGH; delay(100); writereg(); } for(int i = 15; i>0; i--)
{
registers[i] = LOW;
delay(100);
writereg();
}
}
///////////////////////////////////

Shifting Forward!

If you are able to use two shift registers, you will be able to chain 3, 4 or 10 of them. Make sure to always verify the maximum current you can supply; this may impact your circuits performance or even damage your Arduino board.
Video Tutorial: Click Here.
74HC595 Datasheet: Click Here

Comments 1

  1. hi brother! is it posible to grouping the shift register out put? like (grouping in two),turn on (one group) two out put one after the other group, and is it also pisible to drive motor sevo? if it’s possible would you like to share the code

Leave a Reply

Your email address will not be published.

CommentLuv badge