Introduction: Measure the Distance With the Ultrasonic Sensor HC-SRF04

About: Arduino KIT is a place to share content about Arduino programming, Esp8266, and sensors such as SRF04, DHT11, humidity help students learn and study.

What is the ultrasonic sensor (distance)? An ultrasound (Sonar) with high-level waves that people cannot hear. However, we can see the presence of ultrasonic waves everywhere in nature. In animals such as bats, dolphins ... use ultrasonic waves to communicate with each other, to hunt or locate in space.


Code: Download

Step 1: Ultrasonic Sensor (HC - SRF04)

Ultrasonic sensor HC-SR04 (Ultrasonic Sensor) is used very popular to determine the distance because the price is cheap and quite accurate. The HC-SR04 ultrasonic sensor uses ultrasonic waves and can measure distances between 2 -> 300cm.

Step 2: Principle of Operation

To measure the distance, we will emit a very short pulse (5 microSeconds) from Trig pin. After that, the ultrasonic sensor will generate a HIGH pulse at Echo's feet until it receives a reflected wave on this battery. The width of the pulse will be equal to the time the ultrasonic wave is transmitted from the sensor and back. The speed of sound in the air is 340 m / s (physical constant), equivalent to 29,412 microSeconds / cm (106 / (340 * 100)). When the time is calculated, we divide by 29,412 to get the distance.

Note: The further the ultrasonic sensor is, the more incorrect it will be captured, because the scanning angle of the sensor will gradually expand in a cone, in addition to the oblique or rough surface, it will reduce the accuracy of the sensor and parameters. The technique listed below is from the manufacturer of the test under ideal conditions, but in fact depends on the working environment of the sensor.

Step 3: Components

  • Arduino Uno R3
  • Ultrasonic sensor (SRF-04)
  • Breadboard

Step 4: Related Article