ShiftRegister74HC595 Arduino Library

The ShiftRegister74HC595 Arduino Library simplifies shift registers usage. It allows you to set single pins of your shift register either high or low, just like normal Arduino pins. It thereby removes the overhead of shifting out bytes that were created with complicated bit-wise operations. Setting for instance the second pin of your shift register would simply look like sr.set(2, HIGH);

[This page was previously hosted at shiftregister.simsso.de and has been moved from there.]

   

Getting Started

Download the library and install it.

Connect the shift register to your Microcontroller as shown in Figure 1.

Figure 1: One shift register wired up to be controlled by an Arduino UNO.

Open up a new project in the Arduino IDE and import the library with the following code:

#include <ShiftRegister74HC595.h>

Create an instance of the ShiftRegister74HC595 class with:

int numberOfShiftRegisters = 1; // number of shift registers attached in series
int serialDataPin = 0; // DS
int clockPin = 1; // SHCP
int latchPin = 2; // STCP
ShiftRegister74HC595 sr (numberOfShiftRegisters, serialDataPin, clockPin, latchPin);

If you want to use multiple shift registers in series, connect them as shown in Figure 2 and increase the numberOfShiftRegisters variable accordingly. To operate multiple shift registers in parallel, keep numberOfShiftRegisters = 1 and instantiate multiple ShiftRegister74HC595 objects with different pins.

Figure 2: Two shift registers are connected to an Arduino UNO in series, i.e. behind each other.

Insert the normal setup and loop function.

Congratulations! Now you have additional output pins (Fig. 3 – series resistors are left out for clarify reasons). You can access them with a bunch of methods, some of which are explained below:

Set a specific pin of your shift register on high:

int pin = 0;
sr.set(pin, HIGH);

Set all pins:

// either on high ...
sr.setAllHigh();
// ... or low
sr.setAllLow();

Sets all pins at once (pin 0 low, pin 1 high, …):

uint8_t pinValues[] = { B10101010 };
sr.setAll(pinValues);

Set multiple pins at once when using two shift registers in series:

uint8_t pinValues[] = { B00011000, B10101010 };
sr.setAll(pinValues);

You can also read the current state of a pin:

int pin = 0;
uint8_t state = sr.get(pin); // 0 = LOW, 1 = HIGH

An example sketch can be found here.

Contribute

Since the initial release of the library in November 2014, four people have contributed to the library with pull requests on GitHub. If you miss features or have ideas for improvements please consider contributing them by forking the repository and opening a pull request. Be sure to test the changes thoroughly beforehand.

Sample Project

Below is a sample project I have implemented using the shift register library. If you want your shift register library project to be featured here feel free to email me.


(55 Posts)
Software developer with SAP and Denk Development, Computer Science student at Baden-Württemberg Cooperative State University. Interested in programming, math, microcontrollers, and sports.
View all author’s posts