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
- 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.
- 02TT motor 1:48 (200 rpm at 6 V with no load) and 65 mm wheel. Funduino and SunFounder spec sheets.
- 031,158 µs and 19.86 cm come from the model: 1158 × 0.0343 ÷ 2 = 19.86.


