Interfacing: How to Make an Arduino Uno UltraSonic Range Finder!

By Jeff Salim
Arduino Ultrasonic range finder

A range finder is a device used to find the distance from a point to the nearest obstacle. This device uses ultrasonic technology to measure the distance. You can consider it like an electronic, hassle-free version of a measuring tape with a measuring range of 2cm to 400cm and an accuracy of 1cm. Typical applications for an Arduino ultrasonic range finder include parking sensors, obstacle warning systems, level controllers, and terrain monitoring devices. You can make your own Arduino ultrasonic range finder in less than an hour using cheap and easily available components.

Required Materials

Hardware:

  1. HC-SR04 (Ultrasonic Ranging Module )
  2. Arduino Uno
  3. 16×2 Alphanumeric LCD (JHD162A)
  4. Jumper Wires: Male to Female
  5. Arduino Power Jack Connector
  6. 9V battery

Software:

Arduino IDE

How Does it Work?

Arduino Ultrasonic Range FinderFor this range finder, we use an UltraSonic sensor to measure the distance between two points. The principle of operation for this sensor is measuring the distance traveled by sound in a given time. The sensor generates high-frequency sound waves which hit the nearest obstacle and create an echo. The time taken for the echo to reach the sensor is determined. This is used to calculate the distance since the speed of sound in air is a known constant(343m/s). We can display this information on an LCD in centimeters or inches. All these actions are controlled using an Arduino. Let’s have a look at the HC-SR04 ranging sensor now!

Arduino Ultrasonic Range Finder

  • VCC: 5V supply voltage is given to this pin.
  • Trigger: A 10uS long pulse is given to this pin to trigger the transmission. Upon receiving a valid trigger pulse, the HR-SR04 issues eight 40KHz pulses. The time taken by these pulses to reflect back is measured and the distance is calculated from it.
  • Echo: At this pin, the HC-SR04 outputs a signal whose high time is proportional to the range.
  • Ground: Ground is connected to this pin.

 

Arduino Ultrasonic Range Finder

16×2 Alphanumeric Display (LCD)

Setting up the Connections for Your Arduino UltraSonic Range Finder

 

Arduino Ultrasonic Range Finder

 

Connect the ultrasonic sensor and LCD to the Arduino as shown in the diagram above.

 

Uploading the Code to Your Arduino

If you are new to Arduino, download the Arduino IDE (Integrated Development Environment). Now upload the code given below to the Arduino Uno using IDE:

#include "NewPing.h"
#include "LiquidCrystal.h"
#define trig 0
#define echo 13
#define maximum 200

int usec;
int cm;
float inch;
NewPing sonar(trig, echo, maximum);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
lcd.begin(16,2);
}

void loop(){ 
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Range Finder");
usec=sonar.ping();
cm=usec/58;
inch=usec/58/2.54;
lcd.setCursor(0,1);
lcd.print(cm);
lcd.print("cm");
lcd.setCursor(7,1);
lcd.print(inch);
lcd.print("inch");
delay(250);
}

The <NewPing.h> library can be downloaded the <NewPing.h> library. Download this zip file, unzip it into a folder, name it NewPing, and open the Arduino software/Sketch tab/Include Library/Add .ZIP Library/Choose the Zip file, and upload the program to your Arduino Board.

For communicating with the Arduino ultrasonic range finder module, library function <NewPing.h> is used. The jobs of sending the 10uS trigger pulse, waiting for the echo and measuring the width of the echo etc are done by the library function. Just one line of code: usec=sonar.ping() will make the Arduino do all the jobs said above and the width of the echo pulse in micro seconds will be stored in the variable usec. Dividing the pulse width in uS by 58 will give the distance in cm and dividing the pulse width in uS by 148 will give the distance in inches. An “if – else” loop is used for selecting the unit according to the position of the SPDT selector switch.

That’s about it! All you need to do now is make an enclosure.

Package all the electronics neatly into a sturdy box of your liking and you have your very own Arduino ultrasonic range finder. I have installed all my electronics into a spare wooden box I had lying around, here is a picture of it.

 

Arduino Ultrasonic Range Finder

I arranged the ultrasonic sensor on one side and the display on the other. All I need to do now is aim and measure!! :)

 

Watch the video below to see the Arduino Ultrasonic Range Finder in action!

 

 

 

 

 

 

Recommended Posts
Showing 2 comments
  • ajithparma
    Reply

    I found you’re blog via Google and I have to say. A Massive Thank you so much, I believed your article was extremely informative
    I will revisit to see what further great information I can receive here.

  • chanky
    Reply

    dude where is the wiring portion ?? you showed the portions which we already knew,…!!!

Leave a Comment

90 − 85 =

Start typing and press Enter to search