This article will take you through the Serial In, Parallel Out shift register. Learning to use the shift register with Arduino can be a bit intimidating initially.
Once you complete this article, I am sure you will be comfortable using the shift register.
At the end of this article, you will have all the details needed to build your first Arduino and shift register project.
I will take you through the necessary information to understand how a shift register works, the pin out, and the pin description of the 74Hc595 IC.
In the later sections, you will find a step-by-step guide to connecting a 74HC595 IC to the Arduino.
You will also find several example projects and simulations where you can tinker with the code and see the results instantly.
Let’s get started.
Components Needed To Build Project With A Shift Register
Hardware Components
- Arduino Uno Rev3 x 1
- 74HC595 ICs x 1
- Dupont wire x 2
- Arduino USB cable (for powering and programming) x 1
- Breadboard x 1
Software
Quick Tip: Buy the through-hole version of the ICs, which come in through-hole PCB style. Through-hole pins are easy to connect to the breadboard.
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com.
What Is A Serial In Parallel Out Shift Register – 74HC595?
74HC595 is an 8-bit Serial In Parallel Out (SIPO) shift register. The shift register accepts data serially and provides the data on an 8-bit bus.
The shift registers are famous among hobbyists since they are straightforward to use.
The shift register 74HC595 accepts data serially. You only need three GPIOs on your MCU to communicate.
The protocol is straightforward. The information on the data line will be latched by the serial input of the IC on every rising edge of the clock line.
Let us see a functional pin diagram and the pin description of a SIPO shift register.
We can see an 8-bit shift register that accepts the data with respect to the rising edge of the clock. The remaining two blocks are the latch and the output data register.
In simple terms, every time you provide a clock pulse, the data on the data input pin moves one bit inside.
Every time you push the data bit, all the existing bits move one bit aside to make room for the new bit.
Once you have pushed all the 8-bits, you can then transfer the data onto the output pins.
You do this using the storage latch signal.
-> Read our guide about What You Can Build with Adruino.
Pin Details Of An 8-bit Shift Register
I am presenting the pin details of a shift register from Diodes.Inc. The link for the datasheet is here.
Depending on the package you choose, the pin numbers will vary.
So, I will provide you with the pin name and the description. The function of the pins remains the same (for a part from TI or from NXP), but the labels may differ slightly.
Pin label | Pin Description |
Q0 | Parallel output data bit 0 |
Q1 | Parallel output data bit 1 |
Q2 | Parallel output data bit 2 |
Q3 | Parallel output data bit 3 |
Q4 | Parallel output data bit 4 |
Q5 | Parallel output data bit 5 |
Q6 | Parallel output data bit 6 |
Q7 | Parallel output data bit 7 |
GND | Ground connection |
Q7S | Serial clock output pin. This pin is needed when you cascade two or more shift registers to increase the number of outputs further. |
MR# | Master Reset Input. This is an active low input pin. When you drive a low on this pin, the data bits reset to zero (this pin is independent of the clock) |
SHCP | Shift Register Clock Input |
STCP | Storage Register Clock Output |
OE# | Output Enable Input |
DS | Serial Data Input |
VCC | Supply Voltage |
What Pins Of 74HC595 Are Needed To Connect To Arduino?
At a minimum, you need only three pins on the Arduino to connect to the shift register. DS, STCP, and SHCP are those three pins.
If you need to enable/disable the outputs, you must also use the OE pin.
If not, you can leave the 8 data pins always enabled.
Here is one screenshot from the simulation, where you can see the minimal connections needed between the Arduino and the shift register.
You can always choose to change the Arduino pins based on your project. In the above example, we have used three Arduino pins. I have summarized the information in the table below.
Arduino Pin | Shift Register Pin | Description |
2 | DS | Serial data pin. This is the output pin for the Arduino |
3 | SHCP | Shift Register Clock Input. This is the output pin for the Arduino |
4 | STCP | Storage Register Clock pin. This is the output pin of the Arduino |
How To Cascade Two 74HC595 Shift Registers?
The shift registers can be connected in series to increase the number of available outputs.
For example, by combining two 8-bit shift registers in the cascade, you can control 16 independent digital outputs.
You still use only three Arduino pins.
In the table below, you can see the required pin mapping to follow to connect three shift registers.
All you need to mind are the three steps below:
- Connect all the SHCP and the STCP pins of the two shift registers to the Arduino
- Connect the Data pin of the Arduino to the first shift register’s DS pin
- Connect the first shift register’s Q7S pin to the DS pin of the second shift register
Arduino Pin | Shift Register 1 Pin | Shift Register 2 Pin | Shift Register 3 Pin |
2 | DS-1 | N.C. | N.C. |
3 | SHCP-1 | SHCP-2 | SHCP-3 |
4 | STCP-1 | STCP-2 | STCP-3 |
N.C. | Q7S-1 | DS-2 | |
N.C. | N.C. | Q7S-2 | DS-3 |
… | … | … | … |
Step-By-Step Instructions To Connect SIPO Shift Register To An Arduino
The following sections will show you how to connect an 8-bit shift register 74HC595 to an Arduino.
In the end, you will also get Arduino sketches, example codes, and permanent links to the Arduino simulations, where you can also tinker with the code and see the results immediately.
Project 1: 8-bit Shift Register and Arduino to control 8 LEDs
Here is the final connection diagram where you control 8 LEDs using only 3 Arduino Pins!
Let’s get started.
Step 1: Start with the Arduino UNO
Start with the Arduino. We will need about one Arduino UNO, one Shift register, 8 LEDs and connecting wires.
Step 2: Start with the Ground Connections
Notice the Pin number 1 indicator. The GND pin is the 8th pin on the shift register. Connect it to any of the GND pin on the Arduino UNO.
Step 3: Connect the Serial Data line
Connect the DS pin of the shift register to Pin 2 of the Arduino. In your code, you have to set the data pin as GPIO 2 of the Arduino as well.
Step 4: Connect the SHCP line
Connect the Shift register clock input pin to Pin 3 of the Arduino.
Step 5: Complete the STCP pin connection
Connect the Storage register clock input pin to Pin 4 of the Arduino.
Step 6: Output Enable Pin connection
In this example, we dont control the output enable pin. We want to keep the eight output pins of the shift register enabled all the time.
Hence OE pin is connected to the ground.
Remember that the OE pin is active low. Therefore, the output pins are always enabled by connecting the OE pin to the ground.
Step 7: Connect 8 LEDs to the 8 Output Pins
You can connect a 220 Ω or a 100 Ω resistor for each LEDs to prevent the LEDs from burning out.
The cathode of all the LEDs are connected to the GND pin.
Step 8: 5 V Connection
The 5 V for the shift register comes from the 5 V pin of the Arduino UNO.
Step 9: The Arduino Code
Here is the link for the Arduino sketch. The code below is all you need to control the 8 LEDs using the shift register.
You can see that there are several LED functions in the main() function. You can uncomment the functions which you need to activate.
/* SparkFun Inventor's Kit Example sketch 14 SHIFT REGISTER This sketch was written by SparkFun Electronics, with lots of help from the Arduino community. This code is completely free for any use. Visit http://learn.sparkfun.com/products/2 for SIK information. Visit http://www.arduino.cc to learn about the Arduino. Version 2.0 6/2012 MDG */ // Pin definitions: // The 74HC595 uses a type of serial connection called SPI // (Serial Peripheral Interface) that requires three pins: int datapin = 2; int clockpin = 3; int latchpin = 4; // We'll also declare a global variable for the data we're // sending to the shift register: byte data = 0; void setup() { // Set the three SPI pins to be outputs: pinMode(datapin, OUTPUT); pinMode(clockpin, OUTPUT); pinMode(latchpin, OUTPUT); } void loop() { // To try the different functions below, uncomment the one // you want to run, and comment out the remaining ones to // disable them from running. oneAfterAnother(); // All on, all off // oneOnAtATime(); // Scroll down the line // pingPong(); // Like above, but back and forth // randomLED(); // Blink random LEDs // marquee(); // binaryCount(); // Bit patterns from 0 to 255 } void shiftWrite(int desiredPin, boolean desiredState){ // This function lets you make the shift register outputs // HIGH or LOW in exactly the same way that you use digitalWrite(). bitWrite(data,desiredPin,desiredState); //Change desired bit to 0 or 1 in "data" // Now we'll actually send that data to the shift register. // The shiftOut() function does all the hard work of // manipulating the data and clock pins to move the data // into the shift register: shiftOut(datapin, clockpin, MSBFIRST, data); //Send "data" to the shift register //Toggle the latchPin to make "data" appear at the outputs digitalWrite(latchpin, HIGH); digitalWrite(latchpin, LOW); } void oneAfterAnother() { // This function will turn on all the LEDs, one-by-one, // and then turn them off all off, one-by-one. int index; int delayTime = 100; // Time (milliseconds) to pause between LEDs // Make this smaller for faster switching // Turn all the LEDs on for(index = 0; index <= 7; index++) { shiftWrite(index, HIGH); delay(delayTime); } // Turn all the LEDs off for(index = 7; index >= 0; index--) { shiftWrite(index, LOW); delay(delayTime); } } void oneOnAtATime() { // This function will turn the LEDs on and off, one-by-one. int index; int delayTime = 100; // Time (milliseconds) to pause between LEDs // Make this smaller for faster switching // step through the LEDs, from 0 to 7 for(index = 0; index <= 7; index++) { shiftWrite(index, HIGH); // turn LED on delay(delayTime); // pause to slow down the sequence shiftWrite(index, LOW); // turn LED off } } void pingPong() { // This function turns on the LEDs, one at a time, in both directions. int index; int delayTime = 100; // time (milliseconds) to pause between LEDs // make this smaller for faster switching // step through the LEDs, from 0 to 7 for(index = 0; index <= 7; index++) { shiftWrite(index, HIGH); // turn LED on delay(delayTime); // pause to slow down the sequence shiftWrite(index, LOW); // turn LED off } // step through the LEDs, from 7 to 0 for(index = 7; index >= 0; index--) { shiftWrite(index, HIGH); // turn LED on delay(delayTime); // pause to slow down the sequence shiftWrite(index, LOW); // turn LED off } } void randomLED() { // This function will randomly turn on and off LEDs. int index; int delayTime = 100; // time (milliseconds) to pause between LEDs // make this smaller for faster switching index = random(8); // pick a random number between 0 and 7 shiftWrite(index, HIGH); // turn LED on delay(delayTime); // pause to slow down the sequence shiftWrite(index, LOW); // turn LED off } void marquee() { // This function will mimic "chase lights" like those around signs. int index; int delayTime = 200; // Time (milliseconds) to pause between LEDs // Make this smaller for faster switching // Step through the first four LEDs // (We'll light up one in the lower 4 and one in the upper 4) for(index = 0; index <= 3; index++) { shiftWrite(index, HIGH); // Turn a LED on shiftWrite(index+4, HIGH); // Skip four, and turn that LED on delay(delayTime); // Pause to slow down the sequence shiftWrite(index, LOW); // Turn both LEDs off shiftWrite(index+4, LOW); } } void binaryCount() { // This function creates a visual representation of the on/off pattern // of bits in a byte. int delayTime = 1000; // time (milliseconds) to pause between LEDs // make this smaller for faster switching // Send the data byte to the shift register: shiftOut(datapin, clockpin, MSBFIRST, data); // Toggle the latch pin to make the data appear at the outputs: digitalWrite(latchpin, HIGH); digitalWrite(latchpin, LOW); // Add one to data, and repeat! // (Because a byte type can only store numbers from 0 to 255, // if we add more than that, it will "roll around" back to 0 // and start over). data++; // Delay so you can see what's going on: delay(delayTime); }
Project 2: Control 16 LEDs – Cascading Two Shift Registers
In this project, you will control 16 LEDs using two 8-bit shift registers. The final connection looks like the image below.
Step 1: The Connection Diagram
You can follow similar steps as in project 1 to complete the connection. You can refer to the link here to get access to the wiring diagram.
Step 2: The Arduino Code
/* Arduino code for Individual control over each pin Support for 40+ 74HC595 8 bit shift registers http://bildr.org/2011/02/74hc595/ */ #define DATA_PIN 8 // Pin connected to DS of 74HC595 #define LATCH_PIN 9 // Pin connected to STCP of 74HC595 #define CLOCK_PIN 10 // Pin connected to SHCP of 74HC595 // How many of the shift registers #define NUM_SHIFT_REGS 2 const uint8_t numOfRegisterPins = NUM_SHIFT_REGS * 8; bool registers[numOfRegisterPins]; void setup() { pinMode(DATA_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT); pinMode(LATCH_PIN, OUTPUT); clearRegisters(); writeRegisters(); } bool toggle = false; void loop() { for (uint8_t i = 0; i < 16; i++) { if (i % 2 == 0) { setRegisterPin(i, toggle); } else { setRegisterPin(i, !toggle); } writeRegisters(); } toggle = !toggle; delay(500); } void clearRegisters() { // Reset all register pins for (int i = numOfRegisterPins - 1; i >= 0; i--) { registers[i] = LOW; } } void setRegisterPin(int index, int value) { // Set an individual pin HIGH or LOW registers[index] = value; } void writeRegisters() { // Set and display registers digitalWrite(LATCH_PIN, LOW); for (int i = numOfRegisterPins - 1; i >= 0; i--) { digitalWrite(CLOCK_PIN, LOW); digitalWrite(DATA_PIN, registers[i]); digitalWrite(CLOCK_PIN, HIGH); } digitalWrite(LATCH_PIN, HIGH); }
You can note that the Arduino pins 8, 9, and 10 are connected to data, latch and clock pin, respectively.
-> Read our article about How Easy Is It To Learn Arduino?
FAQs About The Serial In Parallel Out Shift Register And Arduino
This section will answer the most frequent questions about the SIPO (Serial In Parallel Out) shift register and Arduino.
Compiling the questions in one place helps you in finding answers quickly.
If you have more questions, please post them in the comments.
1) What is 74HC595 IC used for?
The 74HC595 is a Serial In parallel Out shift register. The IC accepts the inputs serially with reference to an input clock and can drive up to eight outputs.
You can use this IC to increase the number of output pins of an MCU. You can connect the 74HC595 to an Arduino using three pins.
2) How do I use multiple shift registers in Arduino?
You can use multiple shift registers in cascade. You can connect the ICs in series to further increase the number of outputs without increasing the number of pins used on the Arduino.
Some libraries help you to use multiple 74HC595 ICs in cascade.
The earlier sections of this article have covered in detail connecting multiple SIPO registers in series.
The clock line and the latch line of all the shift registers are connected together.
The data output line from the Arduino goes to the serial input of the first shift register.
The first shift register’s serial data output goes to the second one’s serial data input, and so on.
3) What is an 8-bit shift register?
The 74HC595 is an example of a shift register IC. Shift register IC converts data between serial and parallel formats.
These help to reduce MCU pins usage while interfacing with several LEDs or switches.
For example, you can use two 74HC595 IC to connect 16 LEDs to the Arduino. You will need only three pins on the Arduino.
4) Is 74HC595 a microcontroller?
The 74HC595 is not a microcontroller. The 74HC595 is a high-speed 8-bit shift register.
It accepts the serial data on its serial data pin on every positive transition on the clock pin.
You need an MCU or an Arduino board to work with the 74HC595 shift register.
5) What can I do with a 74HC595?
You can do a lot of things with the 74HC595 shift register IC. Some of the applications of the 74HC595 shift register.
- General purpose Output
- Serial to parallel data conversion
- Capture data and hold the data (latching) for long intervals
- Industrial control, automation, etc
- Kiosks, lighting, gaming pods, etc
Conclusion
This article taught us the basics of shift registers, the connections diagram, and a few example projects.
The shift registers benefitted me in one of my automation projects, where I had to control about 12 linear actuators.
Knowing the applications, you build using the shift registers will be exciting. Please let me know if you have any questions or troubles while working with the shift register. I will be glad to help.
Kindly give your feedback on the article. Did you find this helpful? Do you have any suggestions?
Now it is your turn to propose a topic you would like to learn about next!
Don’t miss sharing the article with your friends!
I am Puneeth. I love tinkering with open-source projects, Arduino, ESP32, Pi and more. I have worked with many different Arduino boards and currently I am exploring, Arduino powered LoRa, Power line communication and IoT.