ESP32-S3 Lab · Day 20 of 30

Eight lights
from three wires

Today a chip joins the crew, and it changes the deal you've been working with. On Day 6 every light cost a pin — ten lights, ten wires. The 74HC595 lets you pay in time instead: you send it the eight bits one after another down a single data wire, tick them in with a clock, then flip them all on together with a latch. Three pins, eight lights — and the flowing pattern turns out to be one bit sliding along a row.

About 30 minutesArduino firstMicroPython optionalThe LED bar returns
Agent assist code TSK-DAY20-SHIFTREG

Hand this to an agent so it can pull the lesson packet and coach you step by step.

01 First, know the pieces

What you need

Six things, one of them a chip with sixteen legs. Tap Define on any part you haven't met — the answer opens as a field note you can read and dismiss without losing your place.

Official manual photo of the ESP32-S3 development board.
Manual photo

ESP32-S3 board

The brain that runs your uploaded sketch.

Official manual image of the ESP32-S3 GPIO extension board.
Manual photo

GPIO extension board

Spreads the pins into rows you can reach and label.

Official manual illustration of the 74HC595 shift register chip with its sixteen pins numbered.
Manual illustration

74HC595 shift register

The chip that turns three wires into eight outputs.

Official manual photo of a ten-segment LED bar graph module.
Manual photo

LED bar graph

The bar from Day 6 — eight of its segments light today.

Official manual photo of a resistor with coloured value bands.
Manual photo

8 × 220 Ω resistors

One per segment to keep each LED's current gentle.

Official manual image of a jumper wire.
Manual photo

Jumper wires (about 15)

Temporary, solder-free connections — the most you've used so far.

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart — schematic on top, the same circuit built on a breadboard below. Click it to enlarge. The chip sits across the breadboard's centre channel, and each connection tells you where the wire goes and why.

Official Freenove circuit — C Tutorial, Chapter 14 (74HC595 & LED Bar Graph), page 133.
GPIO 12 74HC595 DS (pin 14) Carries the byte into the chip one bit at a time.
GPIO 13 74HC595 ST_CP latch (pin 12) One rising edge here presents all eight stored bits at once.
GPIO 14 74HC595 SH_CP clock (pin 11) Each tick tells the chip to take in the next bit.
Outputs Q0–Q7 LED bar via 220 Ω each Eight chip outputs each drive one segment through its own resistor.
OE (chip pin 13) GND Held low so the outputs stay switched on.
MR (chip pin 10) 5V Held high so the chip never clears what it holds.

Mind the chip's notch. The 74HC595 only works one way round — the half-moon notch at one end marks where pin 1 sits, and it must match the chart. Unplug USB before you move any wire.

03 One action at a time

Build it

This is the main path — you can finish the day without opening a single field note. Tap each step as you go to keep your place.

0 / 9 done
  1. Seat the ESP32-S3 on the GPIO extension board and keep USB unplugged while you wire.

  2. Straddle the 74HC595 across the breadboard's centre channel with its notch matching the chart.

  3. Give the chip power — VCC and MR (pin 10) to 5V, GND and OE (pin 13) to ground.

  4. Run the three control wires — GPIO 12 to DS (pin 14), GPIO 13 to ST_CP (pin 12), GPIO 14 to SH_CP (pin 11).

  5. Connect outputs Q0–Q7 to the LED bar, with a 220 Ω resistor in series for each segment.

  6. Check the LED bar's direction against the chart — you saw on Day 6 how easily it reverses.

  7. Compare every wire to the chart before you plug in USB.

  8. Open Sketch_14.1_FlowingLight02.ino in Arduino IDE and upload it.

  9. Watch one lit LED run along the bar and back.

Three wires carry a byte.

The chip is holding eight lights for you. Head to Test & debug to confirm the flow.

04 Read just enough code

Read the code

The sketch keeps one byte, x, and lets its single 1 bit slide left and then right. A small helper, writeTo595, hands each new byte to the chip and latches it onto the outputs. Switch to MicroPython if you'd rather see the same idea in Python — the wiring never changes.

Sketch_14.1_FlowingLight02.ino
int latchPin = 13;          // Pin connected to ST_CP of 74HC595(Pin12)
int clockPin = 14;          // Pin connected to SH_CP of 74HC595(Pin11)
int dataPin = 12;           // Pin connected to DS of 74HC595(Pin14)

void setup() {
  // set pins to output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  byte x = 0x01;    // 0b 0000 0001
  for (int j = 0; j < 8; j++) { // Let led light up from right to left
    writeTo595(LSBFIRST, x);
    x <<= 1;
    delay(50);
  }
  delay(100);
  x = 0x80;       //0b 1000 0000
  for (int j = 0; j < 8; j++) { // Let led light up from left to right
    writeTo595(LSBFIRST, x);
    x >>= 1;
    delay(50);
  }
  delay(100);
}
void writeTo595(int order, byte _data ) {
  // Output low level to latchPin
  digitalWrite(latchPin, LOW);
  // Send serial data to 74HC595
  shiftOut(dataPin, clockPin, order, _data);
  // Output high level to latchPin, and 74HC595 will update the data to the parallel output port.
  digitalWrite(latchPin, HIGH);
}
shiftOut(dataPin, clockPin, order, _data)Sends the byte to the chip one bit at a time — a level on GPIO 12 for each bit, and a clock tick on GPIO 14 to take it in. One call does all eight.
digitalWrite(latchPin, HIGH)The rising edge on GPIO 13 copies all eight stored bits to the outputs in one step, so the whole pattern appears together.
x <<= 1Slides the single 1 bit one place left, so the lit LED takes one step along the bar; delay(50) sets the pace.

05 Understand, don't memorise

How three wires carry eight lights

On Day 6 the bar cost you ten pins because each LED had its own wire, all driven in parallel at the same instant. The 74HC595 makes a different bargain. It accepts the eight bits one after another down one wire, holds them inside, and reveals them together on a signal — so you spend a few microseconds of clocking and get seven pins back. Read what each of the three wires does and the moving light explains itself.

The trade

Time for pins

Ten parallel wires became three because the chip accepts the bits in sequence instead of all at once. You pay in time, and it costs you almost nothing the eye can see.

Data

One bit on the wire

The data pin (DS, GPIO 12) carries a single bit at a time — HIGH for a 1, LOW for a 0. It only ever presents one bit; the value on it changes eight times to send a whole byte.

Clock

Each tick shifts and stores

The chip is a row of eight slots. Every rising tick on the clock pin (SH_CP, GPIO 14) shoves the row one place along and drops the current data-pin level into the empty end. Eight ticks and the whole byte is inside.

Latch

All eight at once

While those eight ticks happen the outputs keep showing the old pattern. A rising edge on the latch pin (ST_CP, GPIO 13) copies the eight inner slots to the eight output pins in one step — which is why you never see the bits crawl in.

shiftOut

One call sends a byte

shiftOut(dataPin, clockPin, LSBFIRST, x) does all eight data-and-clock pairs for you. The sketch wraps it: latch LOW, shiftOut the byte, latch HIGH — send, then reveal.

The light

A bit sliding along

x starts as 0x01, one lit slot among seven dark. x <<= 1 moves that 1 up one place, the next byte goes out, and the lit segment jumps one over. Repeat and the light walks the bar.

The trade 8 bits down 1 data wire, one per clock tickone latch edge → 8 outputs lit together

What the latch buys you

Without it, every LED would flicker as the bits shifted through on their way to their final slot. The latch holds the outputs steady until the whole byte has arrived, then updates them together — you only ever see finished patterns.

Where Day 6's ten pins went, and beyond

Day 6 gave every segment its own GPIO. Here the chip holds all eight states and the board keeps just three wires. The same three can drive far more — chips chain end to end, each passing bits to the next, so three pins can run sixteen, twenty-four, or more outputs.

06 Know it worked

Test & debug

Nothing prints to the screen today — the proof is the light running along the bar in front of you.

What you should see
LED bar
  • One lit LED runs along the bar to one end.
  • It turns and runs back to where it started.
  • The run repeats forever, with a brief pause at each end.

Eight segments take part — the chip has eight outputs, so two segments of the ten-segment bar stay dark. That's correct.

If it doesn't
  • Nothing lights at all? Check the chip's orientation by its notch, then its power — VCC and MR to 5V, GND and OE to ground.
  • Pattern scrambled or jumpy? Re-check the three control wires — DS on GPIO 12, latch on GPIO 13, clock on GPIO 14.
  • One LED never lights? Check that segment's 220 Ω resistor and the bar's direction, just as on Day 6.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: choose the byte, predict the lights

Same working circuit, and the one thing that decides what the bar shows is the byte you send. Instead of watching the sketch shift a bit for you, hand the chip a byte you picked and predict the result before you upload. It fits inside today's 30 minutes.

Predict a pattern

In the first loop, replace the body with a single writeTo595(LSBFIRST, 0b10100101) and a delay(500). Before uploading, count the 1 bits — that's how many segments light — and predict which end holds bit 0. Upload to confirm, and note that LSBFIRST plus the bar's direction decide which segment is which.

Run a pair

Start the first loop with x = 0x03 so two neighbouring LEDs travel together. Predict what the second loop's starting value needs to be before you change it.

Fill the bar

In the first loop, replace x <<= 1 with x = (x << 1) | 1 so each step keeps every light already lit and the bar fills from one end — the chip is holding a growing pattern for you.

08 Learn it with a hand on the tiller

Coach me through it

Every lesson ships with a code and a machine-readable packet, so an agent can guide you with full context.

Lesson code

TSK-DAY20-SHIFTREG

How the agent should behave: guide one physical connection at a time and wait for confirmation, then teach the real idea — a shift register trades time for pins by clocking eight bits in one at a time and latching them out together. Explain the data, clock, and latch roles concretely, and always check wiring, board, port, and USB before changing code.

Keep your place

Finished Day 20?

Mark it complete — it shows on your course map, and your place is saved on this device.

Field note

Shortcut

Prompt copied