TinySkiff ESP32-S3 Lab · Day 26 of 30

Measure the room
with sound

Today you build a tiny depth sounder. The HC-SR04 sends a ping you can't hear, listens for the echo, and the ESP32-S3 times the round trip to work out how far away things are — the same trick a boat uses to read the water beneath it.

About 30 minutesArduino firstMicroPython optionalNo electronics assumed
Agent assist code TSK-DAY26-ULTRASONIC

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, nothing more. 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 image of the HC-SR04 ultrasonic distance sensor.
Manual photo

HC-SR04 sensor

The distance sensor with two round transducers.

Official manual image of a jumper wire.
Manual photo

4 jumper wires

Temporary, solder-free connections.

Official manual screenshot of the Arduino IDE interface.
Manual screenshot

Arduino IDE

Uploads code and opens Serial Monitor.

Official manual page showing the Ultrasonic Ranging sketch and Serial Monitor output.
Manual sketch

Official sketch

Sketch_19.1_Ultrasonic_Ranging.ino

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart. Click it to enlarge. Each connection below tells you where the wire goes and why it's there — hover a row to light it up.

Official Freenove circuit — C Tutorial, Chapter 19, page 172. Production lessons keep this source and attribution.
VCC 5V Powers the ultrasonic sensor.
Trig GPIO 13 The board sends a short "start" pulse here.
Echo GPIO 14 The sensor returns a timed pulse here.
GND GND Gives board and sensor the same zero point.

Check before power. Keep the sensor pins in the order printed on the module — VCC, Trig, Echo, GND — and 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 / 7 done
  1. Place the HC-SR04 so the two round transducers face outward, away from loose wires.

  2. Connect VCC → 5V, Trig → GPIO 13, Echo → GPIO 14, and GND → GND.

  3. Pause and compare your wiring to the chart before powering or uploading.

  4. Open Sketch_19.1_Ultrasonic_Ranging.ino in Arduino IDE.

  5. Upload the sketch to the ESP32-S3.

  6. Open Serial Monitor and set the baud rate to 115200.

  7. Hold a flat object 10–30 cm in front of the sensor and move it slowly closer and farther.

Sounder's live.

Your ESP32-S3 is now reading the room by ear. Head to Test & debug to confirm the numbers.

04 Read just enough code

Read the code

You don't need the whole sketch today — just four lines that do the real work. Switch to MicroPython if you'd rather see the same idea in Python; the wiring never changes.

Sketch_19.1_Ultrasonic_Ranging.ino
#define trigPin 13
#define echoPin 14

pingTime = pulseIn(echoPin, HIGH, timeOut);
distance = (float)pingTime * soundVelocity / 2 / 10000;
#define trigPin 13Names GPIO 13 trigPin so the rest of the sketch reads plainly.
pulseIn(echoPin, HIGH, timeOut)Times how long Echo stays HIGH — that's the raw measurement.
… / 2 / 10000Sound goes out and back, so halve it; the / 10000 just lands the answer in centimetres.

05 Understand, don't memorise

Physics of a ping

The whole day is one loop, running many times a second. It's the same idea as counting the seconds between lightning and thunder.

Send a ping

Trig fires

Trig tells the sensor to emit a short pulse above human hearing.

Wait for echo

It bounces

The pulse hits an object and some of it returns.

Measure time

Echo holds HIGH

Echo stays HIGH for exactly the round-trip time.

Convert

Time → distance

Time × speed of sound gives how far the pulse travelled.

Useful model distance = speed of sound × echo time ÷ 2

Why readings wobble

Real sensors react to object shape, angle, movement, and air. A little wobble is normal — watch the trend, not one number.

Why flat targets help

Flat objects bounce more sound straight back. Curved or soft ones scatter it, so the echo gets weaker.

06 Know it worked

Test & debug

Success and recovery sit side by side, so you never have to go hunting when something looks off.

What you should see
Serial Monitor115200 baud
Distance: 24.31cmDistance: 23.92cmDistance: 24.08cm

A good reading changes when you move the object. Small wobble is fine.

If it doesn't
  • 0 cm or frozen? Check Trig, Echo, GND, and the target's shape.
  • Blank monitor? Confirm 115200 baud, then the board and port.
  • Upload fails? Swap in a data-capable USB cable.
  • Readings jump? Aim straight at a flat object.

07 Make the idea yours

Try this: a mini range log

Same working setup, one new skill: turning a measurement into a judgement. It fits inside today's 30 minutes.

Measure three targets

A book, a wall, and one object you pick. Note the expected distance, the reading, and anything odd.

Choose a threshold

Pick a "too close" distance — say 15 cm. Later that line can become a beep or a warning.

Logbook

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-DAY26-ULTRASONIC

How the agent should behave: guide one physical step at a time, wait for you to confirm, explain terms on request, and always check wiring, board, port, and USB before changing code.

Field note

Shortcut

Prompt copied