HC-SR04 Ultrasonic Distance Sensor Module
Accurate Non-Contact Ranging from 2cm to 400cm
The HC-SR04 is the most widely used ultrasonic ranging module in hobby electronics. It works on the same time-of-flight principle bats and sonar use: a 10-microsecond pulse on the Trigger pin fires a burst of eight 40kHz ultrasonic waves from the transmitter; these travel outward, bounce off whatever object they hit, and return to the receiver. The module then holds its Echo pin HIGH for exactly as long as that round trip took. Since sound travels through air at a known, fairly constant speed (~343 m/s at room temperature), your microcontroller only needs to time that Echo pulse and multiply by the speed of sound - divided by two, since the pulse covers the distance twice - to get an accurate reading in centimeters. Because the measurement is purely acoustic, it works reliably regardless of the target's color, transparency, or lighting conditions, which is exactly where infrared distance sensors tend to struggle. With just two digital pins and no I2C or SPI setup required, it remains one of the fastest sensors to get working on any microcontroller.
Key features
Simple 2-Pin Interface
No I2C or SPI needed - a single Trigger pulse in and an Echo pulse out is all it takes to get a distance reading.
40kHz Ultrasonic Transducers
Dedicated transmit and receive transducers give a clean, reliable echo signal independent of ambient light.
Wide Measuring Angle
A roughly 15° detection cone makes it forgiving for robot-mounted obstacle sensing.
Millimeter-Level Resolution
Timing-based measurement gives sub-centimeter resolution, far finer than most IR distance sensors.
Low Cost, Beginner Friendly
One of the cheapest reliable distance sensors available, with huge community support and example code.
Works Well Indoors
Unaffected by target color or transparency, unlike IR sensors which struggle with dark or glass surfaces.


