Working principle of HC-SR04 Ultrasonic sensor

Default Featured Image

Introduction

The HC-SR04 Ultrasonic sensor is a user-friendly, cost-effective sensor ideal for hobby electronics projects and can also be utilized in home automation applications. This sensor is essentially a sound sensor that uses high-frequency sound waves in the Ultrasonic range to measure the distance between the sensor and the object that is right in front of it. These sound waves are above human hearing, greater than 20 kHz.

In this article, we will discuss how the HC-SR04 Ultrasonic sensor works and how it is able to calculate such an accurate distance using ultrasonic sound waves.

Design of the HC-SR04 Sensor

The HC-SR04 Ultrasonic sensor comes with 4 pins:

  1. VCC – It is the power pin that requires 5 volts DC to operate, with an operational current rating of 15 mA.
  2. Trig – Required for generating Ultrasonic bursts, so that the soundwaves can bounce off of nearby objects.
  3. Echo – This pin is required to go HIGH once the signals are detected by the receiver.
  4. GND – This is also a power pin required to provide a ground connection.

This sensor features two types of transducers:

  • Transmitter TX: Responsible for generating the ultrasonic soundwave when the TRIG pin of the sensor goes HIGH
  • Receiver RX: Listens for a burst of Ultrasonic sound waves by setting the ECHO Pin HIGH until the next burst of Ultrasonic signal is detected.

Operation Principle

There are 4 phases to operating the HC-SR04 sensor.

  1. Set TRIG to HIGH: To generate bursts of Ultrasonic signals, the TRIG pin of the sensor is set to HIGH for a minimum duration of 10 microseconds. The duration can be changed based on how quickly you want the sensor to respond.
  2. ECHO at HIGH: The ECHO pin only goes HIGH when the echo of the ultrasonic sound waves is detected by the receiver. The time at which the ECHO goes HIGH is stored by the microcontroller.
  3. ECHO at LOW: Once no more ultrasonic signals are detected or a second burst of ultrasonic sound waves is detected, the ECHO pin goes low, punching the time at which it went low.
  1. Calculate Distance: Once we find out how long it took for the signal to travel back to the sensor using the duration of how long the ECHO pin stays HIGH, we can use the Equation below to calculate the distance.

Where T is the duration of how long it took for the signal to travel back to the sensor in seconds, while travelling at the speed of sound of 340 m/s.

Applications

  • Distance Measurement: Can be used in robotics systems to measure the distance between a specific object or a position of interest
  • Obstacle Avoidance: Used in robots such as automatic vacuum cleaners to avoid crashing into walls and other objects
  • Level Sensing: Used in home automation systems to measure the level of water or any other fluid.

Conclusion

Now that you know how an Ultrasonic sensor works and how easy it is to use, you can check it out at Flywing-Tech to get yourself one to help you automate and enhance your projects.