
Beginner4/7/2026- Author: IoTSpark Maker
ESP32 + HC-SR04: Measuring Distance via Ultrasound (Quick Test Sample Code)
The HC-SR04 measures distance by emitting a 40kHz ultrasonic pulse and timing how long the reflected wave takes to return (time-of-flight).
hc-sr04khoang-cachsieu-am
4 steps4 components
The HC-SR04 measures distance by emitting a 40kHz ultrasonic pulse and timing how long the reflected wave takes to return (time-of-flight). It's the cheapest and most popular distance sensor — used in obstacle-avoiding robots, water-level measurement, parking alerts, and counting people through a doorway.