HC-SR04 Ultrasonic Tape Measure
Time the echo of a 40 kHz ping and convert microseconds into millimetres — your first sensor that actually measures something physical with sound.
Difficulty: Breadboard. Estimated build time: about 30 minutes. Estimated parts cost: about US$7.50. 3-line bill of materials. Compare supplier offers when available. A digital tape measure built from an HC-SR04 ultrasonic range finder and an Arduino.
Wire the sensor
VCC → +5 V. GND → ground. TRIG → Arduino digital pin 9 (output). ECHO → Arduino digital pin 10 (input). The HC-SR04 board hosts both transducers — orient the round metal cans so they point at whatever you want to measure.
Pulse the trigger
In code: digitalWrite(TRIG, LOW) for 2 µs to clean the line, then HIGH for 10 µs, then LOW. The internal driver on the module turns this 10 µs HIGH into the 40 kHz burst. Without that exact 10 µs pulse the module does nothing.
Time the echo
Use Arduino's pulseIn(ECHO, HIGH, 30000) — it returns the width of the next HIGH pulse on ECHO in microseconds, with a 30 ms timeout (= ~5 m max range, safe). Divide by 58 to get centimetres of distance: distance_cm = pulseIn_µs / 58.
Print and watch
In loop(), print the distance every 100 ms with a 50 ms delay between reads (the module needs ~50 ms recovery between pings, otherwise you read the tail of the previous burst). Wave your hand back and forth in front of the cans; the serial monitor scrolls a live distance trace. Drop a 0.1 µF cap across VCC/GND right at the module if readings jitter — the burst pulls a few hundred mA briefly and undecoupled rails can sag.
Compensate for temperature (optional)
The 343 m/s figure is for 20 °C dry air; sound speed rises ~0.6 m/s per °C. If your build runs outdoors, throw a BME280 alongside and apply v = 331.4 + 0.6·T to the math — accuracy at 4 m goes from ±3 mm to ±1 mm across a normal 0–40 °C range.