Distance measurement using Ultrasonic sensor and Arduino

Distance measurement using Ultrasonic sensor interfacing and Arduino, In this article you will learn about each and everything about very famous ultrasonic sensor HC-SR04. You will also learn how to interface ultrasonic sensor with Arduino Uno R3? What is ultrasonic sensor? Types of ultrasonic sensors available in market, applications of ultrasonic sensor. Programming and hardware part of ultrasonic sensor interfacing with Arduino Uno R3 and at the end of this article you will learn its famous use in distance measurement. Distance measurement using Ultrasonic sensor and Arduino Uno R3.distance measurement using Arduino and Ultrasonic sensor

If you don’t know anything about Arduino, first go through following articles so that you can learn programming part of this article properly.




What is Ultrasonic sensor?

Ultrasonic sensor is distance measurement sensor which use ultrasonic sound waves to measure distance. Ultrasonic sensor use high frequency sound waves of 40 KHz . Ultrasonic sensor consists of two basic modules transmitter and receiver. Transmitter acts as speaker and receiver acts as a microphone. Speaker emits ultrasonic waves and Microphone detect ultrasonic waves which is produced by speaker. Basic functionality of ultrasonic sensor is shown in diagram below :

Ultrasonic sensor working

Ultrasonic sensor working

As shown in above figure one part is acting as speaker which emit ultrasonic waves which after collision with any object return back. These returning waves are detect by Microphone. The time taken by microphone to receive ultrasonic waves from transmitter after collision with any object is used to measure distance. I will discuss it later how this time is used to measure distance from any object. Ultrasonic sensor works on the same principle as radio based radar system.

Applications of Ultrasonic sensor

There are many application of ultrasonic sensor from domestic use industrial use. But some of them are given below :




  • Obstacle avoidance robot
  • Robotics
  • object detection
  • distance measurement
  • liquid level monitoring system
  • Height measurement
  • Agriculture
  • vehicle collision protection

In this article I will discuss only one application of ultrasonic sensor module that is distance measurement. But basics remains same, you can use same procedure to use ultrasonic sensor in your project.

Distance measurement using Ultrasonic module and Arduino Uno

As I have already discussed above, transmitter part of ultrasonic module emits ultrasonic high frequency waves in the form of of pulses. After collision of these waves with any object, these wave detect by microphone. Time taken by these waves from transmitter to receiver is used to measure distance from any object. There are many ultrasonic sensor modules are available in market but I will be using HC-SR04. This ultrasonic module is initiated with pulse of 10us.

The distance from any object is calculated using following formula :

distance = speed x time ;

We know that the speed of sound in air is 20C which is equal to 344 meter per second. The time given in above formula should also be divided by two. Because ultrasonic waves travel from transmitter and then go back to receiver by travelling same distance. So the formula to calculate distance becomes :

Distance = 344 x time / 2 meter ;

HC-SR04 ultrasonic module interfacing with Arduino Uno R3

I am using HC-SR04 ultrasonic sensor in this article. HC-SR04 Ultrasonic module have four pins. Description of each pin is given below:

  • power supply pin Vcc 5 volt operating voltage for HC-SR04 sensor to work properly.
  • Ground pin for zero potential.
  • Trigger signal pin which is used to trigger HC-SR04 module with pulse of 10 micro second.
  • Echo signal pin which is actually a receiver pin and used to listen to Ultrasonic sound wave which return after collision with any object.

Circuit diagram of ultrasonic HC-SR04 module interfacing with Arduino Uno R3 is given below along with connections :

Ultrasonic sensor interfacing with Arduino Uno R3

To download code for above given circuit diagram click on following link :

Code for ultrasonic sensor interfacing with Arduino

if you have any issue after reading this article, let me know with your comment. Kindly don’t forget to share it with your friends thanks 🙂

    We highly recommend EasyEDA for Circuit Design and PCB Prototype

Low Cost PCB Manufacturing & Fabrication Service - EasyEDA   

 PCB Prototype: Only $8.21 for 10pcs,100x100mm PCBs, 2-3 days' delivery    

One Response

  1. Nourhan Mohamed May 7, 2016

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,038 other subscribers