Interfacing IR sensor
with arduino
• An infrared proximity sensor, or IR Sensor, is an
electronic device that emits infrared light to detect
objects and motion in Arduino.
IR sensor with Arduino setup:
[Link] VCC to 5V, GND to Ground, OUT to pin D9
[Link] the Arduino IR sensor code
[Link] the sensitivity potentiometer for the desired
Arduino infrared sensor distance
[Link] with the serial monitor for the IR sensor with
Arduino Uno functionality
How Does an IR Sensor with LED
Arduino Code Work?
The working of the IR sensor module is very simple, it
consists of two main components:
1) the first is the IR transmitter section,
2) the second is the IR receiver .
In the transmitter section, an IR LED is used, and in the
receiver section, a photodiode is used to receive the
infrared signal, and after some signal processing and
conditioning, you will get the output.
• IR proximity sensor works by applying a voltage to the
onboard Infrared Light Emitting Diode, which in turn
emits infrared light. This light propagates through the
air and hits an object, after that, the light gets reflected
in the photodiode sensor. If the object is close, the
reflected light will be stronger, if the object is far away,
the reflected light will be weaker.
Arduino Code
int IRSensor = 9; // connect IR sensor module to Arduino pin D9
int LED = 13; // connect LED to Arduino pin 13
Void setup()
{
[Link](115200); // Init Serial at 115200 Baud
Rate.
[Link](“Serial Working”); // Test to check if serial is
working
pinMode(IRSensor, INPUT); // IR Sensor pin INPUT
pinMode(LED, OUTPUT); // LED Pin Output
}
Void loop()
{
int sensorStatus = digitalRead(IRSensor); // Set the GPIO as Input
if (sensorStatus == 1) // Check if the pin high or not
{
digitalWrite(LED, HIGH); // LED HIGH
[Link](“Motion Detected!”); // print Motion Detected! On the serial
monitor window
}
else
{
digitalWrite(LED, LOW); // LED LOW
[Link](“Motion Ended!”); // print Motion Ended! On the serial
monitor window
}
}