![]() |
VOOZH | about |
Arduino is a microcontroller that requires sensors to sense the surroundings to process and react to it. Ultrasonic Sensor is an electronic device that measures the distance between the transmitter and the obstetrical using ultrasonic sound waves. It converts the sound reflected sound into an electric signal to provide a numeric output.
Ultrasonic waves travel faster than the speed of audible sound because their frequency is lower and wavelength is maximum. The ultrasonic sensor measures the distance depending upon the time taken to receive the wave back, hence it measures the total distance traveled by the sound, which is double the distance between the transmitter and obstacle.
Table of Content
An ultrasonic sensor is an electronic device that calculates the time taken by the ultrasonic wave to travel from the emitter to the receiver. Ultrasound waves travel faster than sound. Therefore, the operation of ultrasonic sensors involves sound waves to determine the distance to an object. A transducer is used to send and receive ultrasonic pulses.
Ultra Sensor haves only 4 pins: Trig, Echo, GND, Vcc. Lets see the components and its functionality with these pins:
Ultrasonic Sensor works upon the principle of sound waves. Ultrasonic sensors transmits short, high-frequency sound waves at regular intervals. These signal moves through the air at the speed of sound. When these signal hits an object, they return back to the sensor as an echo signal, and the sensor itself calculates the distance to the target based on the time delay of the transmission signal and receives an echo.
In order to calculate the distance, this formula is being used:
D = ½ T x C
where,
D is the distance,
T is the time, and
C is the speed of sound (346 meters/second)
Ultrasonic sensor having mainly two component: the transmitter (emits the ultrasonic sound waves) and the receiver (which encounters the ultrasonic sound wave which travels to and from the obstacle).
Code for Ultrasonic Sensor:
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration; // stores time taken to recieve the refleced sound wave
int distance; // stores distance from object
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output Pin
pinMode(echoPin, INPUT); // Sets the echoPin as an Input Pin
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the TrigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds which allows Input from Ultrasonic Sensor
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin and returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
IR Sensor is an electronic device that measure and detects infrared radiation from the surrounding environment. It do not measures the distance between the sensor and the object. It is fast responsive and non atmosphere dependent sensor. It works upon the principle of Infrared Light. Its frequency is high that's why its range is very low. It only detects obstacle in straight line.
There are different types of infrared emitters depending upon wavelength, output power and response time of operation. The infrared sensor consists of two main components:
Note: Collectively an IR LED and an IR PhotoDiode is called an OptoCoupler or PhotoCoupler.
int LEDpin = 13;
int obstaclePin = 10;
int hasObstacle = LOW; // Initialy set for no obsticle
void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop()
{
hasObstacle = digitalRead(obstaclePin);
if (hasObstacle == HIGH)
{
Serial.println("Stop something is ahead!!");
digitalWrite(LEDpin, HIGH);
}
else
{
Serial.println("Path is clear");
digitalWrite(LEDpin, LOW);
}
delay(200);
}
Given Below is the Table between Ultrasonic and IR Sensor
Parameter | IR Sensor | Ultrasonic Sensor |
|---|---|---|
Work Principle | InfraRed Light | Ultrasonic Sound |
Response Time | High | Low |
Atmospheric Impacts | No Impact on Accuracy | Impacts Accuracy |
Measures Distance | No | Yes |
Range | 10cm - 80cm | 2cm - 10m |
Beam Angle | 75 Degree | 30 Degree |
Beam Pattern | Narrow(line) | Conical |
Frequency | 353 THz | 40KHz |
Unit Cost | 750 INR | 130 INR |
Arduino - Ultrasonic Sensor is a multipurpose, low cost, highly useful electronic device which is a part of IOT products development. This sensor can be used to track record of data where Infrared Sensor fails to deliver good performance.