Lesson 2 – Flowing Lights

Flowing LEDs are frequently used in:

  • Industrial control panels
  • Automotive dashboard
  • Consumer appliances such as laundry machines and robot vacuums

In this tutorial, we shall make our own lightshow!

Circuit assembled on a breadboard

Introducing the Shift Register

The 74HC595 is an 8-bit serial shift register with a storage register and 3-state outputs. It’s widely used to expand the number of output pins. This is useful if you’ve maxxed out your GPIO’s.

A shift register receives a serial bit-stream, shifts it into the storage register then outputs all the bits simultaneously via the latch clock

The shift and storage register have different clocks – SRCLK and RCLK

At the rising edge of the shift register clock (SRCLK), a single bit gets shifted into the storage register.

The register clock (RCLK) transfers the full 8-bit value from the shift register to the storage register, updating the outputs all at once.

The contents of the storage register is shifted to the output via the latch clock.

The Circuit

Schematic
Wiring diagram

Program Description

This program controls 8 LEDs connected to a 74HC595 shift register, creating a lighting effect where the LEDs appear to flow in one direction.

The initialization of the control pins for the shift register is performed in the setup() function.

In the loop(), the program continuously cycles through a count-up routine that shifts the active LED from one to the next until it reaches the end, at which point it reverses direction.

This is achieved using bit manipulation to either shift left or right based on the LED’s current position and a fixed delay of one second between movements.

See the flowchart below for more information

Code flowchart

The Results!

Animation 1 – Alternating LEDs

Animation 2 – Trailing Effect

Animation 3 – Chaser Pattern

Animation 4 – Ping-Pong

Animation 5 – Random

Animation 6 – Marquee