Arduino Tutorial #3 – Shift Registers (74HC595) – Controlling Multiple Outputs with Fewer Pins

In the third Arduino Tutorial we are exploring shift registers and the concept of having multiple outputs from fewer Arduino Pins. This is an extremely helpful and useful technique for multiple applications. One simple example is controlling an array of LEDs. Other uses may include multiple motors, different valves and many others. You are basically expanding your output capabilities beyond what a normal Arduino can handle; you are no longer limited by the number of pins!

The code is of medium difficulty; it can appear tricky for a beginner. I strongly recommend that you spend some time to look over the datasheet of the 74HC595 Shift Register before you proceed. It explains what every signal used in this tutorial does. Alternatively, take a look at the extended version of the tutorial where I cover the same: Arduino Tutorial 3 – Extended

Arduino Tutorial 3 Shift Registers
int DS_pin = 8;
int STCP_pin = 10;
int SHCP_pin = 9;

void setup()
{
pinMode(DS_pin,OUTPUT);
pinMode(STCP_pin,OUTPUT);
pinMode(SHCP_pin,OUTPUT);
writereg();
}
boolean registers[8];

void writereg()
{
digitalWrite(SHCP_pin,LOW);

for (int i = 7; i>=0; i–)
{
digitalWrite(STCP_pin,LOW);Arduino Tutorial 3 Shift Registers
digitalWrite(DS_pin,registers[i]);
digitalWrite(STCP_pin,HIGH);
}
digitalWrite(SHCP_pin,HIGH);
}

void loop(){
for(int i=0;i<9;i++) { registers[i] = HIGH; delay(100); writereg(); } for(int i=8;i>0;i–)
{
registers[i] = LOW;
delay(100);
writereg();
}
}

As always, thank you guys for watching/reading and I hope that you learned how to put the shift registers to good use.

Make sure to leave a comment!