Working of IR sensor:
An IR sensor is a type of sensor that detects infrared radiation. Infrared radiation is a type of electromagnetic radiation that is invisible to the human eye. IR sensors are used in a variety of applications, such as motion detection, object detection, and remote control.
The working principle of an IR sensor is based on the principle of photodetection. When infrared radiation hits the sensor, it generates an electrical signal. The strength of the electrical signal is proportional to the intensity of the infrared radiation.
There are two main types of IR sensors: passive and active. Passive IR sensors only detect infrared radiation that is emitted by other objects. Active IR sensors emit infrared radiation and detect the reflected radiation.
Applications of IR sensor:
IR sensors are used in a variety of applications, including:
- Motion detection: IR sensors can be used to detect motion. This can be used for security purposes, such as motion-activated lights or security alarms.
- Object detection: IR sensors can be used to detect objects. This can be used for applications such as self-driving cars or robotics.
- Remote control: IR sensors are used in remote controls to control devices such as TVs, DVD players, and air conditioners.
- Industrial automation: IR sensors are used in industrial automation for applications such as quality control and machine vision.
- Medical applications: IR sensors are used in medical applications such as body temperature measurement and blood pressure monitoring.
How to use IR sensor
To use an IR sensor, you will need to connect it to a microcontroller such as Arduino. Once the sensor is connected, you can write code to control the sensor. The code will typically involve reading the sensor’s output and taking some action based on the output.
For example, you could write code to turn on a light when the sensor detects motion. Or, you could write code to move a robot arm when the sensor detects an object.
Interfacing of Arduino with IR sensor:
To interface an IR sensor with Arduino, you will need to use the following steps:
- Connect the IR sensor to the Arduino.
- Write code to read the sensor’s output.
- Take some action based on the sensor’s output.

Here is a simple example of how to interface an IR sensor with Arduino:
Code snippet
// This code will turn on a LED when the IR sensor detects motion
// Import the necessary libraries
#include <Arduino.h>
// Define the pin that the IR sensor is connected to
const int irPin = 8;
// Define the pin that the LED is connected to
const int ledPin = 13;
void setup() {
// Initialize the serial monitor
Serial.begin(9600);
// Set the IR sensor as an input
pinMode(irPin, INPUT);
// Set the LED as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the value of the IR sensor
int irValue = digitalRead(irPin);
// If the IR sensor detects motion, turn on the LED
if (irValue == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}