This article focuses on the HC-SR04 ultrasonic proximity sensor, highlighting its specs and common applications.
The HC-SR04 is a proximity sensor thatâs very popular amongst makers. Here, we explain how the module works, what you need to know to use one in your projects safely, and discuss the operating basics. Links to the full datasheets are available at the end of the article.
About the HC-SR04
The HC-SR04 is an ultrasonic proximity sensor that tells you whether an object is in front of it, and also provides the distance between the sensor and the object. These sensing abilities make it particularly useful for robots that need to know how far they are away from an object or obstacle, for example, a wall or a piece of furniture that they shouldnât hit.
The module is readily available as a finished breakout board that connects to your existing projects. You can get it from many different manufacturers and suppliers, like Adafruit and Geekreit, and they are usually fully compatible. The only difference is the price and shipping time.
- Length: 4.5 cm (1 Â¾ in)
- Width: 2.0 cm (Â¾ in)
- Height: 1.4 cm (Â½ in)
- Typical price: Around $4
- Supply voltage: 5V
- Operating voltages: 3V or 5V (trigger), 5V all other I/O ports
- Working current: 15mA
- Operating range: 2 cm to 400 cm (1 in - 13 ft)
- Claimed precision: 0.3cm, more realistically: 1cm
- Measuring angle: 15 degrees
Principle of Operation
As described above, the main job of the HC-SR04 is adding ultrasonic distance measuring capabilities to projects. But how does that work? The principle, as well as the usage of the module, are both surprisingly simple.
The HC-SR04 gets triggered by a ten microsecond high signal on the trigger pin. Once it gets pulled low again, the module sends out eight 40kHz sound pulses. If an object is present in the detection range, the sound pulses get reflected by that object, and the module receives the echo. The time between sending the eight pulses and receiving the echo can be used to calculate the distance to the object that reflected the sound.
HC-SR04 timing diagram. Image taken from product datasheet.
Checking how long the output pin of the module (usually labeled echo) is high calculates the measured distance. If it is high for longer than 30mS, no object was detected. Please refer to the datasheet of your module for the exact formulas. The recommended time between trigger pulses is 60mS.
There are many HC-SR04 datasheets available on the internet. However, I found these to be the most helpful and the ones that contained the most information:
Projects That Use the HC-SR04
The HC-SR04 is a readily available, cheap, and easy to use ultrasonic proximity sensor module that can be used for a wide variety of projects. Due to its small physical size, itâs also useful for mobile applications, like robots.
Cover image courtesy of Banggood.com