Monday 22 January 2018

Ultrasonic Sensor – How to Use it?

Introduction:

Ultrasonic waves are those which are above human audibility, Ultrasonic sensor uses those sound waves to measure distance between any two devices. It measures distance by sending a sound wave of specific frequency and waiting for that wave to bounce back.
It is also possible that sometimes the sensor might  not be able to detect the objects. This is because sometimes the object is very small or sometimes it is designed in such a way that the reflected wave not travel towards the sensor but in the other direction.

Usage:

Nowadays Ultrasonic sensors are used widely. These are used in different fields like Cell Destruction, Distance Measurement, Dynamic Body Detection, Parking Aid system, etc.

Application:

Project for Reference:


Code:

const int trigPin = 9;
const int echoPin = 10;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, HIGH);

int duration, distance;
// Output pulse with 1ms width on trigPin
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration divided by 29.1
distance = (duration / 2) / 29.1;
Serial.println(distance);
}

No comments:

Post a Comment

SMART BLIND STICK The smart blind stick is the project made to help the blind people who is suffering when walking.It just uses to de...