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!

DHT22 Digital Temperature & Humidity Sensor
Someone in RINGWOOD NORTH bought a
DHT22 Digital Temperature and Humidity Sensor AM2302
about 7 hours ago
 
DHT22 Digital Temperature & Humidity Sensor
Someone in INGLEWOOD bought a
DHT22 Digital Temperature and Humidity Sensor AM2302
about 6 hours ago
 
Someone in PERTH bought a
Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board
about 8 hours ago
 
UNO R3 Board ATmega328P CH340G Arduino Compatible with USB Cable
Someone in AUSTINMER bought a
UNO R3 Board MEGA328P CH340G Arduino Compatible with USB Cable + 1 Item
about 8 hours ago
 
Someone in KATOOMBA bought a
Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board+ 1pcs USB Cable
about 9 hours ago
 
Someone in MARYBOROUGH bought a
Bi-Directional IDE to SATA or SATA to IDE Converter
about 20 hours ago
 
Smoke and Combustible Gas Sensor – MQ2 (LPG, I-Butane, Propane, Methane, Alcohol and Hydrogen)
Someone in KEILOR LODGE bought a
Smoke and Combustible Gas Sensor – MQ2 (Smoke, LPG, I-Butane, Propane, Methane, Alcohol and Hydrogen)
about 1 day ago
 
Breadboard Power Supply Module 3.3V - 5V (Red Wings - MB102)
Someone in WELLARD bought a
Breadboard Power Supply Module 3.3V - 5V (Red Wings - MB102)
about 1 day ago
 
Someone in MOUNT MARTHA bought a
ATTINY85 Digispark USB Development Board - Arduino Compatible
about 1 day ago
 
Someone in MORAYFIELD bought a
25V Voltage Sensor Module
about 1 day ago
 
Share This
X