Measuring Distance using Ultrasonic sensor and Arduino

Measuring Distance using Ultrasonic sensor and Arduino:

Ultrasonic sensor:
        Ultrasonic sensors emit short, high-frequency sound pulses at regular intervals. These propagate in the air at the velocity of sound. If they strike an object, then they are reflected back as echo signals to the sensor, which itself computes the distance to the target based on the time-span between emitting the signal and receiving the echo.

       


      As the distance to an object is determined by measuring the time of flight and not by the intensity of the sound, ultrasonic sensors are excellent at suppressing background interference.

     Virtually all materials which reflect sound can be detected, regardless of their colour. Even transparent materials or thin foils represent no problem for an ultrasonic sensor.


      Microsonic ultrasonic sensors are suitable for target distances from 20 mm to 10 m and as they measure the time of flight they can ascertain a measurement with pinpoint accuracy. Some of our sensors can even resolve the signal to an accuracy of 0.025 mm.

         Ultrasonic sensors can see through dust-laden air and ink mists. Even thin deposits on the sensor membrane do not impair its function.

           Sensors with a blind zone of only 20 mm and an extremely thin beam spread are making entirely new applications possible today: Fill level measurement in wells of microtiter plates and test tubes, as well as the detection of small bottles in the packaging industry, can be implemented with ease. Even thin wires are reliably detected.

  Measuring distance using Ultrasonic sensor and       Arduino:

         Ultrasonic sensor HC-SR04 is used here to measure distance in range of 2cm-400cm with accuracy of 3mm. The sensor module consists of ultrasonic transmitter, receiver and the control circuit. The working principle of ultrasonic sensor is as follows:


  1. High level signal is sent for 10us using Trigger.
  2. The module sends eight 40 KHz signals automatically, and then detects whether pulse is received or not.
  3. If the signal is received, then it is through high level. The time of high duration is the time gap between sending and receiving the signal.
Distance= (Time x Speed of Sound in Air (340 m/s))/2


Components required:

  1. Arduino Uno 
  2. Ultrasonic sensor Module
  3. 16x2 LCD
  4. Bread board
  5. potentiometer-10k
  6. Connecting wires
 Circuit Diagram:

             

      The circuit diagram for arduino and ultrasonic sensoris shown above to measure the distance. In circuit connections Ultrasonic sensor module’s “trigger” and “echo” pins are directly connected to pin 18(A4) and 19(A5) of arduino. A 16x2 LCD is connected with arduino in 4-bit mode. Control pin RS, RW and En are directly connected to arduino pin 2, GND and 3. And data pin D4-D7 is connected to 4, 5, 6 and 7 of arduino.

First of all we need to trigger the ultrasonic sensor module to transmit signal by using arduino and then wait for receive ECHO. Arduino reads the time between triggering and Received ECHO. We know that speed of sound is around 340m/s. so we can calculate distance by using given formula:
Distance= (travel time/2) * speed of sound
Where speed of sound around 340m per second.
A 16x2 LCD is used for displaying distance.
         



Program code:


#include <LiquidCrystal.h>

#define trigger 18
#define echo 19

LiquidCrystal lcd(2,3,4,5,6,7);

float time=0,distance=0;

void setup()
{
 lcd.begin(16,2);
 pinMode(trigger,OUTPUT);
 pinMode(echo,INPUT);
 lcd.print(" Ultra sonic");
 lcd.setCursor(0,1);
 lcd.print("Distance Meter");
 delay(2000);
 lcd.clear();
 lcd.print("Acts Of Facts");
 delay(2000);
}

void loop()
{
 lcd.clear();
 digitalWrite(trigger,LOW);
 delayMicroseconds(2);
 digitalWrite(trigger,HIGH);
 delayMicroseconds(10);
 digitalWrite(trigger,LOW);
 delayMicroseconds(2);
 time=pulseIn(echo,HIGH);
 distance=time*340/20000;
 lcd.clear();
 lcd.print("Distance:");
 lcd.print(distance);
 lcd.print("cm");
 lcd.setCursor(0,1);
 lcd.print("Distance:");
 lcd.print(distance/100);
 lcd.print("m");
 delay(1000);
}

You can visit our YouTube channel Acts of Facts for practical implementation of above project
    click here>> Acts of Facts YouTube     channel
     

Comments

Post a Comment

Popular posts from this blog

Facts about 9V battery

LCD DISPLAY INTERFACING WITH ARDUINO