Arduino Obstacle Avoiding Robot
Level 11 · Level 11 — Don't Crash · 40 minutes
An eye on the front, and a robot that stops before it hits what is in front of it.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Keep Level 9's robot as it is, with no line sensors this time, then add an eye on the front. Wire the HC-SR04: - VCC to 5V, GND to GND - TRIG to D5, ECHO to D4 Drive at least 1500 mm in 8 seconds and turn away before you touch the wall. Spinning on the spot earns no distance.
Components you’ll use
- Arduino Uno
- L298N Motor Driver
- DC Gear Motor × 2
- Battery
- HC-SR04 Ultrasonic Distance Sensor
What you'll build
Your last robot went where the line told it. Now there is no line, just a wall. One eye, and you turn before you hit.
How it works
- The HC-SR04 fires a burst of ultrasound and times the echo. Level 6's trick, now on something that moves.
- There and back, so halve it:
cm = microseconds × 0.0343 ÷ 2. - The eye sits 70 mm ahead of the centre: your first reading is about 153 cm.
The key idea
Clear ahead, drive. Something close, turn. That is the whole program.
Turning is not free. Distance counts the centre's path, so spinning on the spot earns none.
8 s × 200 mm/s = 1600 mm of path at most. You need 1500.
⚠ Watch out
Braking is not turning. The eye reads whole centimetres, so 30 shows with the wall still 310 mm off: about 1220 mm in, 280 mm short. Nothing crashes, so it looks right. It still fails.
The honest limit
One eye measures along a single line, straight ahead. At a shallow angle it reports a long clear diagonal while the robot's shoulder is already scraping. Real robots sweep the eye on a servo.
The interactive editor includes the wiring guide, code editor and simulation controls.