Thursday 29 January 2015

11)Detecting the Distance using a Ultra-Sonic sensor


Ultrasonic sensors works similar to a radar which gets the presence of  target by interpreting the echoes from radio or sound waves . Active ultrasonic sensors generate high frequency sound waves and detects the echo which is received back by the sensor and then measures the time interval between sending resumption of  the echo to determine the distance to an object.

Working


The working of Ultrasonic sensor is just based on how the bat flies, It sends out a ultrasonic wave and waits for its echo to return back if it returns back then it takes a either turn or it continues path.

Now mathematically we define speed = (distance) / (Time);

So this would imply distance=speed * Time;

Parameters known

1)speed of ultrasonic sensor.
2)Time taken for it to strkte an object and echo.  ie  (observed Time /2 ) will be the time to strike the object and return to its original origin.
3)Distance can be found by the desired form.

check the following site to know the speed of ultrasonic sensor in various medium http://www.classltd.com/sound_velocity_table.html

Diagram


Pins on a US sensor

                              1) Vcc
                              2)Gnd
                              3)Trigger ( provide Vcc to send a ultrasonic signal)
                              4)echo      (Rx)


Sketch

//The following program prints the distance in the serial monitor and blinks an LED when distance is less than 10Meters

#define trigger 2
#define echo 3
void setup()
{
   pinMode(trigger,OUTPUT);
   pinMode(echo,INPUT);
   pinMode(13,OUTPUT);
   Serial.begin(9600);
}
void loop()
{
   int time,distance;
   
// Now send out a ultrasonic wave for one second

digitalWrite(trigger,HIGH);
delay(1000); // transmitting a wave for 1 second
digitalWrite(trigger,LOW);

time=pulseIn(echo,HIGH);  // Returns the length of pulse in Micro-seconds  check http://arduino.cc/en/Reference/pulseIn for more info
distance=(time/2)/29.1;        //

Serial.println(distance);

if(distance<10)
{
   digitalWrite(13,HIGH);
}
else
{
  digitalWrite(13,LOW);
}
}

   

No comments:

Post a Comment