Obstacle-Sensing Robot
Build a robot head that sweeps a distance sensor left, center, and right, decides which way is clearest, and signals its choice.
Materials You'll Need
- Elegoo ESP32 Super Starter Kit (ESP32 board, breadboard, jumper wires)
- From the kit: HC-SR04 distance sensor, SG90 micro servo, 2 LEDs + 2× 220Ω resistors, active buzzer, 1K + 2K resistors
- Computer with the free Arduino IDE and a USB cable
- Card → Bot Build Book, Projects 3 and 5 (free PDF in the Hi, Bot Games library)
- Boxes or books to use as obstacles
- This printable sheet
- Pencil
Hi, Bot Track Projects · obstacle-avoiding-robot · Print-friendly · hibot.space/track-projects
How It Works
- 1
Tape the HC-SR04 to the servo arm so the servo can turn it like a head. Wire both as in Build Book Project 5: servo signal GPIO 13, TRIG GPIO 5, ECHO GPIO 18 through the 1K + 2K voltage divider.
- 2
Add a 'left' LED on GPIO 21 and a 'right' LED on GPIO 22, each through a 220Ω resistor, the same as Project 3's green and red LEDs (if you built Project 3, keep them). The buzzer goes on GPIO 19. The LEDs are your robot's steering: they show which way it would turn.
- 3
Start from Project 5's code. Change the loop so the head points left (150°), center (90°), and right (30°), measuring the distance at each. Check that when the code looks left, the head points to the robot's left. If it points right, your servo is mounted the other way: swap 150° and 30°.
- 4
Write your decision rule in the decision table. Example: if center is over 30 cm, go straight (both LEDs). Otherwise turn toward the side with more room. If all three are blocked, buzz and 'back up'.
- 5
Test it: put an obstacle ahead, on the left, on the right, then all around. Record each run in the test log. Did it make the right call?
- 6
Draw your final flowchart. Then tune the 30 cm threshold: what changes at 10 cm? At 60 cm?
Your Work
Head design sketch + decision table + final flowchart + test log. 1 way to fool your robot and how you'd fix it.
Head design
Decision table
| Left (cm) | Center (cm) | Right (cm) | My robot should… |
|---|---|---|---|
Final flowchart
Test log
| Run | Where's the obstacle? | Robot chose | Right call? |
|---|---|---|---|
Parent Notes
Two wiring rules matter: keep the ECHO voltage divider (the sensor sends 5 V, the ESP32 pins take 3.3 V), and if the board resets when the servo moves, power the servo from the kit's breadboard power module with a shared GND. The big idea is sense → think → act: three readings, one rule, one choice. The kit has no wheels, so the LEDs stand in for steering; for a driving version, any 2-motor chassis with a motor driver works, but never run motors straight from ESP32 pins. Ask: 'What would fool this robot? A thin chair leg? A soft pillow?'
Reflect
What did you learn? What was hard? What would you do differently next time?
Made by Hi, Bot. Learn more at hibot.space/track-projects