Range finder using Ultrasonic Sensor

We estimate the distance of an object using ultrasonic sensor and arduino.

Components required

  1. Arduino UNO + USB cable
  2. HC-SR04 Ultrasonic sensor
  3. Male/Female Jumper wires

About the project

Ultrasonic Sensor


We use HC-SR04 module in our project. The module works on principle of transmitting and receiving the ultrasonic waves which is projected towards an object. We send a 10 microseconds signal to the trig pin of the module. This triggers a burst of 40kHz (higher than hearing range) pulses from the sensor. The sensor sends eight of these pulses. After this we use pulseIn() function which calculates the duration of the pulse to return. Pulse function in our case triggers a timer which calculates the propagation delay. This is read via the echo pin. The value read is in microseconds.

We then convert the microseconds read into centimetres and print it in the serial monitor.

Formula



The speed of sound is approximately 340 m/s. So the distance travelled in t microseconds is :

v = 340 m/s

v = 340 x 100 cm/ 1000000 us

v = 0.034 cm/us

v = D / t

D = v x t

Since D = 2 x d (Actual distance of the object, because the wave travels to and fro from the object)

d = v x t / 2

d = (0.034 / 2) x t

Here the distance is in centimeters.

Uploading the sketch and testing the sensor

Find the code to this project here.

Upload the sketch on to the Arduino and then connect the ultrasonic sensor according to the schematics below:

Now, all you need to do is open the serial monitor and view the distances printed and play with it.

What next ?

Ultrasonic sensors are low cost and can be used for various purposes, like a proximity sensor for an autonomous robot, or for a quadcopter, to detect if there is an object close by. 
P.S: Link to my Arduino project hub page for this project: Range finder using Ultrasonic Sensor




































Comments

Popular Posts