The infrared (IR) sensor is one of the most common components in robotics, especially in line-following robots. It allows the robot to “see” black or white lines and react accordingly.
Applications of IR Sensors
An IR sensor consists of two main parts:
Mechanism:
👉 This difference allows the IR sensor to distinguish black vs. white.
A typical IR sensor module has 3 pins:
Some modules include a potentiometer to adjust sensitivity.
Digital IR sensors: OUT gives only 0 or 1.
Analog IR sensors: OUT gives a voltage (0–5V), which Arduino reads with analogRead().
// Example Code to Read Sensor
int irPin = A0; // IR sensor connected to A0
void setup() {
Serial.begin(9600);
}
void loop() {
int value = digitalRead(irPin); // read digital signal
Serial.println(value); // print to Serial Monitor
delay(200);
}
👉 If the Serial Monitor prints 0 → white, 1 → black (depending on sensor type).