Infrared (IR) Sensor

📌 Table of Contents

1. Introduction

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

2. Working Principle

An IR sensor consists of two main parts:

Mechanism:

👉 This difference allows the IR sensor to distinguish black vs. white.

3. Structure & Pin Connections

A typical IR sensor module has 3 pins:

Some modules include a potentiometer to adjust sensitivity.

4. Output Signals

Digital IR sensors: OUT gives only 0 or 1.

5. Code


// 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).