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 TELOPEA bought a
DC-DC 6-24V to 5V 3A Car USB Charger Module Buck / Step down Converter
about 2 hours ago
 
Someone in MACQUARIE FIELDS bought a
Fitbit One Wireless Activity and Sleep Tracker USB Charging Cable Adapter
about 2 hours ago
 
Someone in BURPENGARY bought a
5V 1 Channel 240V AC Solid State Relay
about 9 hours ago
 
Someone in WYNNUM WEST bought a
64 LED Matrix Panel WS2812 5050 RGB LED Module
about 9 hours ago
 
Someone in COLLAROY bought a
DS18B20 Digital Temperature Waterproof Sensor Probe for Thermometer - 1 Meter
about 10 hours ago
 
MT3608 Step-Up Adjustable DC-DC Switching Power Module Boost Converter
Someone in CHADSTONE bought a
MT3608 Step-Up Adjustable DC-DC Switching Power Module Boost Converter + 2 Items
about 16 hours ago
 
Someone in MANLY VALE bought a
Arduino Nano 3.0 Atmel ATmega328 Mini-USB Board
about 1 day ago
 
300 MBPS WIRELESS WIFI USB LAN ADAPTER – RASPBERRY PI, MAC, OSX, WINDOWS, LI
Someone in FITZROY NORTH bought a
300 Mbps Wireless Wifi USB LAN Adapter - Raspberry Pi, Mac, OSX, Windows, Linux
about 1 day ago
 
Someone in SYDNEY bought a
IC 2262 / 2272 4 Channel 315Mhz Wireless Remote Control Kit + 1 Item
about 1 day ago
 
Someone in BUNINYONG bought a
USB 3.0 TO GIGABIT RJ45 ETHERNET LAN ADAPTER 1000 MBPS PC & MAC
about 1 day ago
 
Share This
X