
HC-SR04 is the name of one of the most popular ultrasonic sensors. It is used to measure distances through the emission of high frequency sound wavesIn this post we explain all the details of how it works.
It is a model that is found present in numerous projects created through the open source electronics platform ArduinoThere are many reasons for its success: its energy consumption is low (which is why it is a perfect sensor for battery-powered devices), it is easy to interconnect and it is relatively inexpensive.
How Ultrasonic Sensors Work
To understand how the HC-SR04 sensor works, you first need to know What are ultrasonic sensors? (also known as ultrasonic sensors). These are proximity detectors capable of detecting objects at different distances.
Basically, what the sensor does is emit a sound and measure the time it takes for the emitted signal to hit an object and return. The emitted wave is called a "trigger" in technical jargon, while the reflected wave is called an "echo."
This allows you to perform a distance calculation with a very high degree of precision. In this way, sensors like the HC-SR04 can detect objects of different shapes, whether solid or liquid.
The extraordinary degree of accuracy of ultrasonic sensors is largely due to the learning function that are usually incorporated. It must be said that this type of sensor only offers reliable results in environments with the presence of air. They cannot work in a vacuum, since sound needs a medium of propagation.
One of the weaknesses of these sensors is that they cannot do anything against the blind spots, that is, the spaces between the sensitive part of the detector and the minimum range.
Why can't we hear ultrasound? El human ear It is only capable of detecting sound waves that vibrate at a rate of approximately 20 to 20.000 times per second. However, ultrasound has a frequency of more than 20 Hz, which makes it completely inaudible to us.
HC-SR04 Hardware Details
The ultrasonic distance sensor HC-SR04 It is composed of two ultrasonic transducersThe first of them acts as a transmitter and the second as a receiver. transmitting device converts the electrical signal into 40 kHz ultrasonic sound pulses. For its part, the receiving device "listens" to the transmitted pulses and generates an output pulse whose width is proportional to the distance of the object the signal bounced off of.
The device has four pins:
- VCC, to supply power to the HC-SR04 ultrasonic sensor (in a Arduino, can be connected to the 5V output).
- Trig (trigger or trigger), to fire ultrasonic sound pulses.
- Echo. This pin remains HIGH until the sensor receives an echo, after which it goes low.
- GND or ground pin.
This sensor provides a high degree of reliability within a range between 2 cm and 40 meters. We are talking about a margin of error of at most 3 mm. In truth, that is not bad at all.
At greater distances, its accuracy gradually decreases, while at distances less than 2 cm the problem of dead zones referred to above appears. Accuracy may also be lower in environmental conditions of high temperatures or excessive humidity.
Another interesting feature is that, when running on 5V, can be connected directly without problems to an Arduino or any other similar logic microcontroller. In this respect, its compact dimensions are also noteworthy: 45 x 20 x 15 mm.
Operation and distance calculation
This is how the HC-SR04 ultrasonic sensor works, explained very simply:
- The transmitter or Trigger Transmits an eight-pulse ultrasonic burst at 40 kHz (there are eight of them to make it easier to distinguish the transmitted pulses from the ambient noise).
- Right after the broadcast, the echo pin goes to the HIGH position to start the echo signal.
- When the reflected signal returns, echo pin goes low.*
(*) If the signal does not encounter any obstacles within the sensor range, no echo will be received.
From the data generated through the signal emission and its echo, the HC-SR04 control module is able to calculate the distance. It is actually as simple as apply a simple physical formula that we were all taught in our school years (see image above).
Conclusion
The HC-SR04 ultrasonic sensor is An excellent choice for Arduino-based projects geared towards distance measurement and object detection.Its main strengths are its operation, simple but effective (as long as we are talking about short distances), as well as its price, around 10-12 euros.
Editor specialized in technology and internet issues with more than ten years of experience in different digital media. I have worked as an editor and content creator for e-commerce, communication, online marketing and advertising companies. I have also written on economics, finance and other sectors websites. My work is also my passion. Now, through my articles in Tecnobits, I try to explore all the news and new opportunities that the world of technology offers us every day to improve our lives.