Using Shift registers with Arduino

Jan 10, 2019 | Arduino

As we all know, Arduino or any micro-controllers that exist have a limited number of pins. An Arduino has 14 digital pins. So, what if we had to control 7 LEDs or drive something else using it? We would have to use 7 individual digital pins. That is quite a big number of pins. Today, we will learn to overcome that problem by making use of the power of Shift Registers! By using a shift register we can give away 7 or more digital outputs using only 3 Arduino digital pins. The circuit is a bit big, the working principals are a little complex too. But this is a really useful technique that totally is worth knowing.

What is a Shift Register?

The Shift Register is a type of sequential logic circuit that can be used for the storage or the transfer of binary data. Shift registers hold the data in their memory which is moved or “shifted” to their required positions on each clock pulse. The register is loaded with serial data, one bit at a time, with the stored data being available at the output in parallel form. Explaining Shift registers is quite a complex task as there are university courses on it and it is quite a broad topic. So, if you are interested in understanding how this thing works, I strongly recommend you to check the following links out in sequential order.

  • https://www.youtube.com/watch?v=6fVbJbNPrEU
  • https://www.youtube.com/watch?v=fpnE6UAfbtU
  • https://www.electronics-tutorials.ws/sequential/seq_5.html

Shift Register SN74HC595:

For our tutorial today, we will be using the SN74HC595 IC. The SN74HC595 devices contain an 8-bit, serial-in, parallel-out shift register that feeds an 8-bit D-type storage register. The storage register has parallel 3-state outputs. Separate clocks are provided for both the shift and storage register. The shift register has a direct overriding clear (SRCLR) input, serial (SER) input, and serial outputs for cascading. When the output-enable (OE) input is high, the outputs are in the high-impedance state.

SN74HC595 Pinouts:

Circuit Diagram:

The circuit may look a little messy and complex, but don’t worry. It actually isn’t when you start implementing.

The code:

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(1000);
writereg();
}

for(int i = 7; i>0; i--) {
registers[i] = LOW;
delay(1000);
writereg();

}
}

How the Code works:

This code basically turns on all the LED one by one, then turn them off again one by one. Working procedure of the register and the code is a little complex but really awesome when you understand it. Basically, while keeping the SHCP pin low, we set the each of the bits by shooting pulses. After setting all the 8 bits or sending all the pulses to the DS pin, we give a pulse at the STCP pin which executes our given configuration of the bits and the LEDs are turned on as desired. We turn on LEDs one by one, then turn them off one by one again. To understand the process more clearly, I highly recommend you to watch this video: https://www.youtube.com/watch?v=6fVbJbNPrEU It explains the process in a very detailed manner. If you have implemented the project shown here, Congratulations! You are no longer limited to the beginner and basic circuits and projects. Cheers!

Someone in BOWRAL bought a
5mW 650nm Red Line Laser Module Focus Adjustable Laser Head 5V Industrial Grade + 1 Item
about 4 hours ago
 
Someone in POINT CLARE bought a
SOIC8 SOP8 Test Clip with Cable + 2 Adapters for EEPROM 93CXX / 25CXX / 24CXX In-circuit Programming + 1 Item
about 1 day ago
 
Someone in STRATHFIELD SOUTH bought a
Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board + 1 Item
about 2 days ago
 
Someone in MT WAVERLEY bought a
Raspberry Pi 3 Model B+
about 2 days ago
 
Someone in MELBOURNE bought a
5mW 650nm Red Line Laser Module Focus Adjustable Laser Head 5V Industrial Grade + 1 Item
about 2 days ago
 
Someone in OAKLANDS PARK bought a
USB 3.0 TO GIGABIT RJ45 ETHERNET LAN ADAPTER 1000 MBPS PC & MAC
about 2 days ago
 
Someone in GLENWOOD bought a
AM/FM Portable Radio with USB MP3 Player LED Torch 10 Hour Battery Life
about 2 days ago
 
MT3608 Step-Up Adjustable DC-DC Switching Power Module Boost Converter
Someone in ALKIMOS bought a
MT3608 Step-Up Adjustable DC-DC Switching Power Module Boost Converter
about 3 days ago
 
Someone in MAYFIELD WEST bought a
ST-Link V2 ST-Link Mini STM In-Circuit Programmer and Debugger for STM8 and STM32 – with Cover + 2 Items
about 3 days ago
 
Someone in TURRAMURRA bought a
Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board
about 3 days ago
 
Share This
X