Chapter 4: Surface Return

Day 18: The surface seems so much closer

Video lesson · 35 min

The surface is close but a massive sea creature blocks your path. Build a sonar-like monitoring system using shift registers to control many LEDs with few pins. Learn serial communication and output expansion with the 74595 chip.

The Surface Beckons

The water around your lander stirs with an ominous presence. Through the murky depths, sensors detect movement above—massive, calculated, patient. Rachel, the colossal sea creature that destroyed your previous ascent attempt, circles somewhere in the darkness between you and the surface. Her sonar pings echo through the water like a predator's heartbeat, each pulse a reminder that she's hunting.

Your lander sits motionless on the ocean floor, sixty meters below the surface that represents salvation. The hull creaks under pressure while emergency lights flicker across your makeshift control panel. Every component salvaged from the wreckage has led to this moment—the keypad from yesterday's security system, the seven-segment depth gauge, and now your most critical tool: a rotary encoder that will control your ascent rate.

This isn't a race to the surface. One wrong move—too fast, too slow, too erratic—and Rachel will strike again. The encoder's precise clicks echo through the cabin as you test the mechanism. Twenty clicks for a full rotation, each one representing careful control over your vessel's vertical movement. The mathematics are brutal in their simplicity: rise too quickly and the water pressure differential could tear your hull apart; too slowly and you'll drain what little power remains in your backup systems.

Your depth gauge glows with an amber -60, the number that separates you from breathable atmosphere. Between you and zero lies a gauntlet of pressure zones, mechanical limitations, and a creature whose intelligence rivals your own desperation. The surface seems so much closer than it did yesterday, but distance means nothing when precision means everything.

What You'll Learn

When you finish this mission, you'll be able to:

Control your lander's ascent rate using a rotary encoder—a precision input device that translates rotational movement into directional commands. You'll master the concept of interrupts, a programming technique that lets your microcontroller respond instantly to critical events without constantly checking sensors.

Build a depth monitoring system that tracks your position between the ocean floor and surface, complete with warning alerts at critical ascent points. You'll implement milestone detection to prevent catastrophic pressure changes that could compromise your hull integrity.

Combine multiple sensors into a cohesive control system—the seven-segment display from yesterday's lesson now becomes your primary depth gauge, while the new encoder provides the precise control needed for safe ascent through hostile waters.

Understanding Rotary Encoders

Think of a rotary encoder as a sophisticated volume knob that remembers everything. Unlike a simple potentiometer that measures position, an encoder tracks movement—how far you turn it and which direction. Every satisfying click you feel corresponds to a precise angular measurement that your microcontroller can interpret.

The magic happens through two internal signals called CLK (clock) and DT (data). As you rotate the encoder, these signals pulse in a specific sequence. When CLK goes high before DT, that's clockwise rotation. When DT beats CLK to the punch, that's counterclockwise. This timing-based detection is called quadrature encoding, and it's the same principle used in everything from computer mice to industrial machinery.

Your encoder provides 20 distinct positions per full rotation, giving you 18 degrees of precision per click. That's fine enough control to adjust your lander's ascent rate in tiny increments—crucial when the difference between gradual rise and structural failure might be just a few degrees of encoder movement.

The key advantage over other input methods is continuous operation. Unlike buttons that you press and release, or keypads with discrete values, the encoder turns endlessly in both directions. This makes it perfect for controlling values that need to increase or decrease smoothly over time—like the depth of a spacecraft rising through water where sudden changes could prove fatal.

Wiring Your Depth Control System

Wiring diagram showing rotary encoder and seven-segment display connections
  1. Rotary Encoder Power: Connect VCC to HERO Board 5V and GND to ground. The encoder needs clean power for reliable signal generation.
  2. Critical Interrupt Pins: CLK connects to pin 2, DT connects to pin 3. These MUST use pins 2 and 3 because the HERO Board only supports interrupts on these pins.
  3. Seven-Segment Display: CLK to pin 6, DIO to pin 5. These are the same connections from yesterday's keypad lesson—your depth gauge.
  4. Leave SW Pin Unconnected:

This is lesson 19 of 31 in 30 Days Lost in Space — a professionally produced Arduino course taught by Dr. Greg Lyzenga (NASA JPL scientist, Harvey Mudd professor). Each lesson features cinematic-quality video produced with a 20-30 person professional crew.

All video lessons are free to watch. Get the kit at craftingtable.com — $100 with a 30-day money-back guarantee.