Pure Electronics

←Index

Shift Registers

How to use a SN74HC595 Shift Register

by Professor Petabyte

 

Equipment

If you want to reproduce the experiments in this video yourself, you will need:-

Schematic of Shift Register Demo

Zoomable Image
Mouseover to Zoom
The SN74HC595 is a commonly used 8-bit serial-in, parallel-out shift register IC. It's especially popular in embedded and microcontroller projects (like Arduino and Raspberry Pi) where you want to control many outputs (like LEDs) using just a few GPIO pins.

Photo of Demo Breadboard

Zoomable Image
Mouseover to Zoom
Photo of working setup. Note that the Resistor pack (8A221G) in the foreground has only 7 outpins, therefore 3 additional resistors have been added (bottom right) to serve the 3 rightmost LEDs of the 10 LED strip. The leftmost pin of the resistor pack has a lead to Ground on the Pico driving this setup. The three resistors connect to the Ground rail of the breadboard which is also connected to Ground on the Pico driving this setup.

Python Code for Shift Register Demo

         1 import machine
         2 import utime
         3 SER_pin = machine.Pin(16, machine.Pin.OUT, machine.Pin.PULL_DOWN) #SERial data in
         4 OCL_pin = machine.Pin(17, machine.Pin.OUT, machine.Pin.PULL_DOWN) #Output CLock
         5 OEN_pin = machine.Pin(18, machine.Pin.OUT, machine.Pin.PULL_UP)   #Oput ENable
         6 ICL_pin = machine.Pin(19, machine.Pin.OUT, machine.Pin.PULL_DOWN) #Input CLock
         7 CLR_pin = machine.Pin(20, machine.Pin.OUT, machine.Pin.PULL_UP)   #Master CLeaR
         8 
         9 bitlist=[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0]
        10
        11 t=0.1
        12 
        13 #Init
        14 def InitSR():
        15     CLR_pin.value(0)
        16     SER_pin.value(0)
        17     CLR_pin.value(1)
        18     OCL_pin.value(1)
        19     OCL_pin.value(0)
        20 
        21 
        22 InitSR()
        23 while True:
        24     for bit in bitlist:
        25         #Put bit onto serial pin
        26         SER_pin.value(bit)
        27 
        28         #Move bit into memory
        29         ICL_pin.value(1)         
        30         utime.sleep(t)
        31         ICL_pin.value(0)
        32 
        33         OCL_pin.value(1)
        34         OCL_pin.value(0)
        35 
        36     InitSR()
        

How it Works

Here is a line by line description of the code example.
Note that the Pin numbers below are GPIO Pin numbers on the Pico - NOT Pin numbers on the Shift Register.

  1. Machine library is imported for Pin control
  2. Time library needed for to make timing delays
  3. Define Serial Pin - Used to input bits to the shift register on GPIO6
  4. Define Output Clock pin
  5. Define Output Enable pin
    Key details about the OEN pin:
    Typical Use:
  6. Define Input Clock pin
    The Input Clock Pin (pin 11) on the 74HC595 shift register is commonly labeled as SHCP or SRCLK (Shift Register Clock). It is responsible for shifting data into the shift register. Key Function: Important Notes:
  7. Define Master Clear pin
    The Master Clear pin (pin 10) on a 74HC595 shift register is used to reset (clear) the shift register.
    Key Properties of the Master Clear (CLR) Pin:
  8. Define list of bits to be sent to shift register
  9. Define a value for pauses (slows processing to enable it to be seen)
  10. [comment denoting Initialisation routine]
  11. Function Initialising Shift Register
  12.   Set Master Clear low to clear Shift Register
  13.   Set Serial Pin low
  14.   Reset Master Clear high
  15.   Set Output Clock high, and then ...
  16.   Set Output Clock low to reset the output latches to reflect the cleared shift register.
  17. Call function InitSR to inialise Shift Register
  18. Start of repeat forever loop
  19.   Loop to fetch bits from 'bitlist' one at a time
  20.     [comment 'put bit onto serial pin']
  21.     Set bit value (0 or 1) onto Serial In pin
  22.     
  23.     [comment 'Move bit into memory']
  24.     Set Input Clock pin to high denoting need to move bit into shift register (and move existing bits along)
  25.     Brief pause (to enable this to be seen)
  26.     Set Input Clock pin back to low
  27.     
  28.     Set Output Clock pin high to move (all 8) bits in shift register to output register
  29.     Set Output Clock pin back to low
  30.     
  31.     When loop through bitlist isa completed, rerun Initialisation routine ready for next iteration through bitlist

Types of Shift Resigter

There are five main types of shift registers, classified by their input and output data types: Serial-In/Serial-Out (SISO), Serial-In/Parallel-Out (SIPO), Parallel-In/Serial-Out (PISO), Parallel-In/Parallel-Out (PIPO), and a Universal shift register. Here's a breakdown:

Types of SIPO Shift Resigter

A common Serial In/Parallel Out (SIPO) shift register IC is the 74HC595. It's used to control a large number of outputs, like LEDs, because it shifts data serially into the register and then provides parallel outputs. Another example is the 74HC164, also an 8-bit SIPO shift register.

Difference between an SN74HC595N shift register and a SC74HC164N shift register

The SN74HC595N and 74HC164N (sometimes prefixed by "SC" depending on manufacturer) are both 8-bit serial-in shift registers, but they have different features and use cases. Here's a detailed comparison:

πŸ†š SN74HC595N vs 74HC164N
FeatureSN74HC595N74HC164N (SC74HC164N)
TypeSerial-in, Parallel-out (SIPO)Serial-in, Parallel-out (SIPO)
Output Latchesβœ… Yes – includes output latches (storage register)❌ No – outputs change immediately with shift
Number of Outputs8 Q outputs8 Q outputs
Serial Inputs 1 (SER or DS) 2 (A and B, ANDed together)
Clock Pinβœ… Yes (SRCLK)βœ… Yes (CLK)
Latch Pinβœ… Yes (RCLK – registers output to Qs)❌ No latch – outputs directly reflect shift register
Output Enable (OE)βœ… Yes (active low)❌ Not available
Cascadingβœ… Easy via Q7β€² (serial out) βœ… Possible – via Q7 or QH
Use CaseIdeal for driving LEDs or displays with stable outputSimple serial shift register

Functional Differences

SN74HC595N: 74HC164N:
Two registers Single shift register
One shift register (receives bits via serial input). One storage register (outputs data when latched). Outputs reflect the immediate state of the shift register - they update as data is shifted in.
You clock data in, and then latch it out. Very useful when you want to load new data without flickering or affecting outputs during the shift No control over when data appears on the outputs.

Summary:

Use SN74HC595N when:

Use 74HC164N when:

The SN74HC595 and SC74HC164N (also known as 74HC164) are both 8-bit serial-in, parallel-out (SIPO) shift registers, but they differ significantly in features and behavior:

Core Differences

FeatureSN74HC595SC74HC164N (74HC164)
Output Latch (Storage Register)βœ… Yes β€” has a latch for output control❌ No β€” outputs follow shift register directly
Output Enable (OE)βœ… Yes (active low)❌ No
Serial Inputβœ… 1 (SER)βœ… 2 (A and B, internally ANDed)
Clock Pinβœ… SRCLK (Shift Register Clock)βœ… CLK
Latch Pinβœ… RCLK (Register Clock β€” controls output update)❌ Not available
OutputsQ0–Q7 (buffered, latched)Q0–Q7 (direct from shift register)
Cascading Capabilityβœ… Easy with Q7β€² (serial out)βœ… Possible via Q7
Use CaseStable, flicker-free updates (LED drivers, displays)Simple shifting tasks




© 2025 Professor Petabyte