Drive 8 LEDs with 3 pins using a 74HC595 shift register.
This is a common circuit - appears in most Arduino tutorial series.
I/O pins are finite resource, hence the many techniques to multiplex output. This approach uses a shift register to provide an 8-bit wide output. Shift registers can be chained to provide even more bandwidth.
The 74HC595 is driven using only 3 digital pins:
- latch pin (ST_CP)
- clock pin (SH_CP)
- Data in (DS)
The latch pin is taken low while a new value is loaded. The new value is presented to the shift register output pins when the latch is taken high.
Data is loaded with the clock and data pins. When the clockPin goes from low to high, the shift register reads the state of the data pin.
So to shift out 8 bits we need 8 cycles.
We could do this bit by bit, but in this case we can use the
shiftOut function to shift out a whole byte in one command.
Credits and references
- 74HC595 datasheet
- Based on the Arduino ShiftOut example
- Adafruit Eight LEDs and a Shift Register tutorial
- Arduino Tutorial #3 - Shift Registers (74HC595) video by EEEnthusiast
- Introduction to 74HC595 shift register – controlling 16 LEDs - protostack.com.au