Horje
Ultrasonic Sensor Vs IR Sensor

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.

What is an Ultrasonic Sensor?

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.

Arduino Ultrasonic Sensor-2

Ultrasonic Sensor

Components and Pin Diagram of Ultrasonic Sensor

Ultra Sensor haves only 4 pins: Trig, Echo, GND, Vcc. Lets see the components and its functionality with these pins:

  • Transmitter: It transmits ultrasonic waves when input signal is provided to the sensor using the Triger Pin(Trig).
  • Receiver: It receives the transmitted ultrasonic wave and measures the total distance and send the output to the Echo Pin, which takes the data to the micro controller for further operation.
  • Vcc Pin: This is a power source pin which provides power supply to the sensor.
  • GND Pin: This is a ground pin which neutralize the power from the sensor and mention the flow of current in the circuit.

Features of an Ultrasonic Sensor

  • Supply voltage: 5V (DC).
  • Supply current: 15mA.
  • Modulation frequency: 40Hz.
  • Output: 0 – 5V (Output high when obstacle detected in range).
  • Beam Angle: Max 15 degrees.
  • Distance: 2 cm – 400 cm.
  • Accuracy: 0.3cm.
  • Communication: Positive TTL pulse.

Working Principle of Ultrasonic Sensor

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

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);

}

What is an IR Sensor?

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.

IR Sensor

IR Sensor

Features of an Infrared (IR) Sensor

  • Supply Voltage: 5V (DC)
  • Supply Current: 20mA
  • Modulation Frequency: 38kHz
  • Output: Digital signal (0 or 1) (Output high when obstacle detected)
  • Detection Range: 2 cm – 30 cm (varies based on model)
  • Beam Angle: Approximately 35 degrees
  • Accuracy: ±0.5 cm
  • Communication: Digital output (compatible with microcontrollers)

Components of IR Sensor and its Working

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:

  • An infrared LED: This is an emitter which emits light waves which hits the object.
  • An infrared Photodiode: This is used to receive the reflected light waves which was hit by the object.

Note: Collectively an IR LED and an IR PhotoDiode is called an OptoCoupler or PhotoCoupler.

Code for IR Sensor

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);

}

Difference Between Ultrasonic and IR Sensor

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

Conclusion

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.

Ultrasonic Sensor – FAQs

What is the price of Ultrasonic Sensor?

Usually ranges between 125 to 250 INR, depending upon quality of product.

From where we can buy?

Robu.com is a reliable website for electronic products.

How to learn Arduino?

YouTube is the best source to learn IoT.




Reffered: https://www.geeksforgeeks.org


Arduino

Related
Arduino - Water Detector / Sensor Arduino - Water Detector / Sensor
Arduino Integrated Development Environment (IDE) v1 Arduino Integrated Development Environment (IDE) v1
Arduino Coding Basics Arduino Coding Basics
Arduino - Temperature Sensor Arduino - Temperature Sensor
Arduino - Ultrasonic Sensor Arduino - Ultrasonic Sensor

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11