Introduction: Arduino Distance Measure Using Ultrasonic Sensor

About: Electronic and Telecommunications Engineer

Arduino distance measurement using ultrasonic sensor HC-SR04

Ultrasonic sensors are great tools to measure distance without actual contact and used at several places like water level measurement, distance measurement, obstable avoiding robot and many more. This is an efficient way to measure small distances precisely.

In this project we have used an Ultrasonic Sensor to determine the distance of an obstacle from the sensor. When sound waves are transmitted in environment then waves are return back to origin as ECHO after striking on the obstacle. So we only need to calculate the travelling time of both sounds means outgoing time and returning time to origin after striking on the obstacle.

As speed of the sound is known to us, after some calculation we can calculate the distance.

Let's start,

Step 1: Required Hardware

  • Arduino uno/nano
  • Ultrasonic sensor (HC-SR04)
  • Jumper Wires
  • Breadboard (optional)

Step 2: Required Software

Arduino Sofrware : Arduino IDE

Step 3: Connecting the Hardware

  • Arduino pins need wired are below:
  • pin 10 on Arduino ---> on ultrasonic -- trig Pin
  • pin 9 on Arduino ---> on ultrasonic-- echoPin
  • Vcc on Arduino ---> on ultrasonic pin Vcc / +5v
  • Gnd on Arduino ---> on ultrasonic pin Gnd

Step 4: Circuit Diagram

Make the connections.

Step 5: Setting Up Arduino IDE

For selecting board follow the steps, Go to Tools ==> Board ==> search for Arduino Uno and select this , then select com port .

Download the skecth below the link , and open code,

Now upload the source code.

Step 6: Code

Code for Project Code Link

Step 7: Final Step

After the successful upload of code you will message Done , then open serial monitor here you will distance from obstacle.

and here you are finish with project , Enjoy your project.
That’s it for this tutorial. Thanks for reading.

If you have any question about today’s tutorial, please feel free to share via the comment section

I hope it will helpful to you...........................Thanks.

Step 8: My Another Project