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);
Getting Started
Download the library and install it.
Connect the shift register to your Microcontroller as shown in Figure 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 with:
int numberOfShiftRegisters = 1; // number of shift registers attached in series int serialDataPin = 0; // DS int clockPin = 1; // SHCP int latchPin = 2; // STCP ShiftRegister74HC595<numberOfShiftRegisters> sr(serialDataPin, clockPin, latchPin);
Note: When using the pins 0
and 1
, they cannot be used for the serial connection anymore. If you want to use statements like Serial.println
, you should connect the shift register to other pins, e.g. 2
, 3
, and 4
.
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.

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, five 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.
Your library is excelent, work with 74hc164 only with two lines, data and clock and deleting latch.
Thanks, glad to hear that! The latch pin can be indeed set to be the clock pin, if the use-case does not suffer from having short glitches which will then occur while shifting new data into the register.
would have liked if you gave an example of how to read the binary number from an a pot and update it it real time on an 8 bit LED strip….That’s what I am trying with your library…I must say I love it…Not sure if that would be possible for you to put in the documentation. Basically I want in the end to display a thermocouple reading to a display
I am trying to compile downloaded code that seems to be using a non-template version of the library, e.g.
“ShiftRegister74HC595 shift(3, 13, 14, 15);”
Is the broken compile related to a change December 20, 2019?
Is there a way to get the backwards compatible API, or am I forced to modify the code to get it to compile?
If there is a non-backwards compatible change, then it would be nice to document it. Thanks for all your efforts making this library!
Hey Carl, you are right, the change made in this PR was not backwards compatible. The version should have been increased to 2.0.0 probably. In your example you are good by changing
ShiftRegister74HC595 shift(3, 13, 14, 15);
toShiftRegister74HC595<3> shift(13, 14, 15);
. I’m not sure if there is a way to change the code such that old versions will not break, however, I think the change is so small that people will be able to upgrade easily.Hey Denk,
I’m using the ti SN74HC595 in an arduino project, based on the datasheet pin 13(OE) is active low.
since the arduino takes some fraction of a millisecond for the arduino code to start the moment the
circuit is powered on, the 74hc595’s leds are HIGH until the arduino code starts to drive the OE HIGH
hence turning off the outputs.
Is there any clever wiring i could implement to keep the OE HIGH thus disabling the outputs long enough for the arduino to be on to drive the IC??
connecting the OE directly to vcc will do the trick but it wouldn’t make sense since i wouldn’t be able to enable it
every time i turn the circuit on, the leds immediately flashes on and off in a blink before
things starts going.
I only want to prevent this from happening.
Regards,
Chase
Hey Chase,
you might want to look into pull-down/pull-up resistors. Here is a link on that topic.
Let me know whether it helps. 🙂
Best, Timo
Can you give an code example for assigning pins to a 2nd 74hc595.
Sure, you might do something like that:
which will let you make calls like
srA.set(1, HIGH)
orsrB.set(1, HIGH)
, addressing two different shift register pins.Hi Timo, I am hoping using 4 x74HC595 daisy chained and an Arduino Nano for sequentail turn signals and have it working, the issue is i need to have an input on the nano activate the 74HC595’s to run the sequence
For example if I want to flash once it will compete 1 sequence or if I want it to flash 10x thats thats 10 complete sequences
Thanks
Hi,
I was using your library to make a scoreboard. If you push a button some leds on a stip will light up.
It work just fine but my led stip is made of a blue led a red and a green one but the blue leds are not working. Any idea what I should do ?
Looking for some help here. I have this setup with 2 shift registers i want to be able to start at 0 0 and count up and down using switches. Anything you can suggest to get me going on the right track?
Hi Timo ,
can i use this library also for the dm13A ???
Peter
First of all my compliments for the perfectly working library, which I’m presently using with 4 x TPIC6C595N in series.
I was asking myself if the library would work also with a mix of TPIC6C595N and 74HC595: Have you ever tasted such a configuration ?
There is any limitation in the number of shift register in series ?
Is it possible to define multiple instances of serial registers as, for instance:
Thanks for your kind comment. I have never tested the library with another shift register. If you happen to do it, it would be very nice if you could let me know how it went.
Secondly, there is no limitation on the number of shift registers you can operate in series other than the memory of the microcontroller.
You can use shift registers in series and in parallel at the same time. In fact I am working on a project right now where I use three shift registers in series and another stack of four shift registers in series and it works without any problems.
IF i have to use 3 74hc595 , if i need to use this function sr.setNoUpdate(0, HIGH);
what is the number of the pin 7th output of the 3rd 74595
sr.setNoUpdate(22, HIGH);
is it true or false ???
What you’re saying is correct. The indices just continue counting up. The first shift register is from 0 to 7, the second from 8 to 15, the third from 16 to 23, and so on.
thank you very much
Dear Timo
is there library for 74165 can do the opposite function of 74595?
Thanks to you, Timo, for the prompt answer !
Yes, your library works perfectly also with the TPIC6C595N, which is shift register with open drain outputs (https://www.ti.com/lit/ds/symlink/tpic6c595.pdf?HQS=TI-null-null-digikeymode-df-pf-null-wwe&ts=1593491135208)
Hi, thank you so much for this library. It works amazing with 18 of the 74HC595 daisy chained together. Very simple, lightweight, and effective.
I’m having difficulty using the OE pin and PWM though. When I have the duty set to 0 it all works as it should. As soon as I apply any other duty at all (say i use 26 or 10%), it activates all the of the pins at once. I can not seem to figure out why.
Do you know why using PWM would suddenly set all pins HIGH on all shift registers?
Hi.
For pin ZERO led turned ON then automatic turned OFF. For all other pin it works well.
Board-ESP32
The problem is most likely caused by the double pin-allocation of pin 0 and 1 when using the
Serial
output. To resolve the problem you can either stop usingSerial.begin(9600);
or place the shift register on any digital pin other thanD0
andD1
.I have updated the article accordingly.
Hi Timo
Thanks for this library.
Can you advise how the decimal points are accessed?
Hi and thanks! The library is agnostic to what you connect. If you work with a seven-segment display, you might just use pin 8 of the shift register for the decimal dot.
Thanks Timo
I’ll explore that suggestion
I build a test circuit for the 74HC595 and run the example code. I dont know if im using it right, but for every loop in loop function everything stops for 5-10s.
Hi Timo,
I’m a beginner on Arduino and I’m trying to control the light intensity of several LEDs according to the value of potentiometers (each potentiometer has an assigned LED).
I use a 74HC4051 for the potentiometers (it works very well).
I also tried the 74HC4051 for the LEDs but I always get a residual voltage that turns on the LEDs that shouldn’t be.
Can you tell me if it is possible to use a 74HC595 to do this (Actually i tried it but i didn’t manage to do it well) ?
Thank you
This vworks fine, thanks! I have four of them chained, and I can drive four 7 segment digits, but one question remains: when I press reset, or send a new code to the Arduino, it doesn’t start to run the routine of counting 1 to 9999 but gives me 8 in the last digit while the others work fine.