Shift Register 74HC595 Arduino Library

more output pins. more possibilities.

Timo Denk

The Shift Register 74HC595 Arduino Library makes the use of shift registers much easier.

It basically allows you to set single pins of your shift register either high or low, instead of shifting out complicated created bytes. So you can simply increase the number of output pins on your microcontroller without much more work. Source code on GitHub

Get started!

Download the library and install it. Connect the shift register to your Microcontroller as shown in Fig. 1.

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 like so:

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 Fig. 2.

You can create multiple instances of the shift register class if necessary. In fact this makes sense if you want to use multiple shift registers parallel and not in series.

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:

// sets a specific pin of your shift register on high
int pin = 0;
sr.set(pin, HIGH); // equivalent to sr.set(pin, 1);

// sets all pins either on high ...
// ... or low

// sets all pins at once (pin 0 low, pin 1 high, ...)
uint8_t pinValues[] = { B10101010 };

// set multiple pins at once when using two shift registers in series
uint8_t pinValues[] = { B00011000, B10101010 };

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 of using the library can be found here.

That's it from me! Feel free to contact me if you have any questions or want to give feedback. The legal information for this site can be found here.

Snake - an example project

An example project that makes use of shift registers and the ShiftRegister74HC595 Arduino Library to control an LED matrix with 64 LEDs using actually only six output pins of the Arduino. Snake source code on GitHub

List of all functions

ShiftRegister74HC595(int numberOfShiftRegisters, int serialDataPin, int clockPin, int latchPin);
void setAll(uint8_t * digitalValues);
uint8_t * getAll();
void set(int pin, uint8_t value);
void setAllLow();
void setAllHigh();
uint8_t get(int pin);

Contact / Feedback