Skip to content
robotips

Lab 01

Sonar: a robot that listens to walls

An obstacle-avoiding robot that builds itself, 32 parts from code. The HC-SR04 sends out 8 pulses at 40 kHz and the Arduino turns the echo into centimeters.

Published on

Lab 01Sonar: a robot that listens to walls
Isometric drawing of a two-wheeled robot with an Arduino UNO, L298N H-bridge, HC-SR04 sensor and two 18650 batteries, with its indigo shadow on the paper.
Loads when you tap it, 361 KB
Lab 01. The robot doesn't see the wall: it listens to it.
Share on X

What you will see

The classic obstacle-avoiding robot: Arduino UNO, HC-SR04 sensor, L298N H-bridge and 2 TT motors. It assembles itself, piece by piece, and then runs the real sketch.

The sensor sends out 8 pulses at 40 kHz, which you can't hear because they are above 20 kHz. The echo takes 1,158 µs to come back and the Arduino turns it into 19.9 cm. Below 20 cm, the robot stops, backs up and turns.

Move the threshold and see where it stops.

Model note

What the lab assumes and where its numbers come from.

Model: HC-SR04 (10 µs TRIG pulse, 8 cycles at 40 kHz, 2-400 cm, 15°, ≥ 60 ms between readings), sound at 343 m/s (20 °C), 65 mm wheels, TT motors 1:48. Assumption, not a measured value: 25 cm/s at PWM 150. Move the THRESHOLD and the robot stops at a different point.

Sources

  1. 01HC-SR04: 10 µs TRIG, 8 cycles at 40 kHz, 2-400 cm, 15°, more than 60 ms between readings, µs/58 = cm. ElecFreaks datasheet.
  2. 02TT motor 1:48 (200 rpm at 6 V with no load) and 65 mm wheel. Funduino and SunFounder spec sheets.
  3. 031,158 µs and 19.86 cm come from the model: 1158 × 0.0343 ÷ 2 = 19.86.

On the roadmap

More labs

Isometric drawing of an orange multimeter measuring a 9 V battery and reading 9.42 V, next to a wall outlet, a breadboard and a coffee cup.

Lab 02

Multimeter: its 10 functions

The multimeter's 10 functions, each with something you have on your desk: a battery, the wall outlet, an LED or an Arduino's PWM.

Isometric drawing of a blue Arduino UNO connected with two wires to a breadboard with a red LED and a 220 Ω resistor.

Lab 00

Blink: your first program

Your first Arduino program, seen from the inside: pin 13 switches between 5 V and 0 V, and that turns the LED on and off.

Lab 01