Arduino Ultrasonic Radar with Servo Scanning
Level 13 · Level 13 — Look Around · 45 minutes
A sensor on a servo, sweeping side to side — so the robot can see the wall it is turning into, not just the one it is facing.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Keep Level 11's robot. Add Level 12's servo, with the sonar mounted on its horn — that is what makes the eye turn. Wire it up: - Servo: signal to D3, red to 5V, brown to GND Sweep right, ahead and left. Remember all three. Then drive for 40 seconds in a closed room: 4 metres covered, nothing touched.
Components you’ll use
- Arduino Uno
- L298N Motor Driver
- DC Gear Motor × 2
- Battery
- HC-SR04 Ultrasonic Distance Sensor
- SG90 Micro Servo
What you'll build
A robot whose eye turns. The sonar rides on a servo horn — the arm that swings — and looks three ways, not one.
How it works
- Servo signal goes to
D3, not D9 or D10: the L298N owns those, and the Servo library takes Timer1 — the chip clock behind their PWM. - Aim with
eye.write(angle):40 = right, 90 = ahead, 140 = left. - Store all three readings in an array — a small map of the room.
The key idea
Level 11's eye was bolted down. Meet a wall at a shallow angle and the beam reads far away. Your shoulder is already scraping it.
The fix is a better look, not cleverer code. Look where you are about to go, not only where you are pointing.
The room is closed. Cover 4 metres in 40 seconds, touching nothing:
4000 mm ÷ 40 s = 100 mm per second
⚠ Watch out
Your loop() already has delay(60) after eye.write(). Keep it. The library sends the servo's pulse only about every 20 ms, and the horn keeps its old angle until that pulse arrives. Ping sooner and you store the old direction's distance under the new angle, then steer into the wall you just called clear.
The interactive editor includes the wiring guide, code editor and simulation controls.