In this blog, we will be discussing interfacing ultrasonics sensor with Arduino Uno.
# Sensor Data Sheet:
Working Voltage: 5V
Working Current: 15mA
Range: 2cm - 4m with an angle of 15 degrees
Maximum Trigger Pulse: 10 MicroSeconds
# Pin-Out:
Vcc = 5V ... Power Supply Pin
Trigger Pin: Send a pulse to trigger pin (Output Pin)
Echo Pin: Recieve the pulse from Echo Pin (Input Pin)
Gnd ... Power Supply Pin
# Arduino Connection:
# Working:
Ultrasonic Sensor basically consists of a Transmitter and a Reciever.
When it receives an input pulse at the trigger pin, it transmits ultrasonic waves.
These waves get reflected by the object and are captured by the receiver.
It then receives the pulse from the echo pin.
The time taken by the signal is calculated by Arduino.
And the speed of the Ultrasonic Waves is fixed = 334m/s
Then the distance of the object can be calculated using the formula...
Speed = Distance / Time
=> Distance(Unknown) = Speed (Constant)* Time (From sensor)
# Arduino Code:
int trig_pin = 3; //define your trigger pin here
int echo_pin = 4; //define your echo pin here
float distance; //distance will be measured in cms
void setup() {
pinMode(trig_pin,OUTPUT);
pinMode(echo_pin,INPUT);
Serial.begin(9600);
}
void loop() {
distance = ultrasonic_sensor_data(trig_pin,echo_pin);
Serial.println(distance);
}
float ultrasonic_sensor_data(int x,int y)
{
float duration;
float distance_temp;
float speed_of_ultrasonic = 334; //speed of ultrasonic waves in air
digitalWrite(x, LOW);
delayMicroseconds(2);
digitalWrite(x, HIGH);
delayMicroseconds(5);
digitalWrite(x, LOW);
duration = pulseIn(y,HIGH);
distance_temp = (( speed_of_ultrasonic * duration )*100)/2;
return distance_temp;
}
# Applications:
1. Object Detection
2. Distance Calculation
Good information
ReplyDelete