Infrared obstacle sensors are the building blocks of line-following robots, edge detection systems, and proximity triggers. These tiny modules emit IR light and detect the reflection, outputting a digital HIGH or LOW signal based on whether an object (or a line on the ground) is present within their detection range. At ₹30-50 per module, they’re one of the cheapest sensors available and a staple of robotics competitions and college projects across India. This guide covers the working principle, wiring, and complete builds for line follower robots and object detection systems.
How IR Obstacle Sensors Work
An IR obstacle sensor module has two components: an IR LED (transmitter) that emits infrared light at ~940 nm wavelength, and a photodiode or phototransistor (receiver) that detects reflected IR light. When an object is within range, IR light bounces off it and reaches the receiver. An LM393 comparator on the module converts this to a digital output.
Key characteristics:
- Detection range: 2-30 cm (adjustable via potentiometer)
- Output: Digital (LOW when object detected, HIGH when clear) — note: this is inverted on some modules
- Angle: ~35° detection cone
- Response time: <2 ms
Colour Sensitivity
IR sensors are affected by surface colour. White surfaces reflect IR light well (strong signal = object detected at longer range). Black surfaces absorb IR light (weak signal = object not detected or detected only at very close range). This colour sensitivity is actually useful — it’s what makes line-following possible.
Types of IR Sensors
Single IR Obstacle Sensor
The standard module with one IR LED and one receiver. Used for proximity detection, obstacle avoidance, and single-point line detection. Cost: ₹30-50.
IR Line Tracking Sensor (TCRT5000)
The TCRT5000 is a reflective optical sensor in a compact package. It’s more precise than generic IR modules for line following because the emitter and detector are close together and shielded from ambient light. Available as single modules or pre-built arrays of 3-5 sensors on one PCB.
Multi-Channel IR Array
3-sensor or 5-sensor arrays on a single board, designed specifically for line-following robots. The array gives you the line position (left, centre, right) in one reading. A 5-sensor array also detects intersections and line width.
Arduino Wiring and Basic Code
| Sensor Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | D2 |
const int irSensor = 2;
const int led = 13;
void setup() {
Serial.begin(9600);
pinMode(irSensor, INPUT);
pinMode(led, OUTPUT);
}
void loop() {
if (digitalRead(irSensor) == LOW) {
// Object detected (most modules output LOW on detection)
digitalWrite(led, HIGH);
Serial.println("Object detected!");
} else {
digitalWrite(led, LOW);
Serial.println("Clear");
}
delay(100);
}
Line Follower Robot Project
A line follower robot uses IR sensors to detect a dark line (black tape) on a light surface (white floor). The sensor reports LOW over the black line (IR absorbed, no reflection) and HIGH over the white surface (IR reflected back).
Components
- Arduino Uno/Nano — ₹250-400
- 3-channel IR sensor array — ₹80-120
- L298N motor driver — ₹120
- 2x DC geared motors with wheels — ₹200
- Robot chassis — ₹150
- Battery pack (4x AA or 7.4V Li-ion) — ₹100-300
- Total: ₹900-1,400
// 3-Sensor Line Follower
const int LEFT_SENSOR = 2;
const int CENTRE_SENSOR = 3;
const int RIGHT_SENSOR = 4;
// L298N motor driver pins
const int ENA = 5, IN1 = 6, IN2 = 7; // Left motor
const int ENB = 10, IN3 = 8, IN4 = 9; // Right motor
const int SPEED = 150; // 0-255
void setup() {
pinMode(LEFT_SENSOR, INPUT);
pinMode(CENTRE_SENSOR, INPUT);
pinMode(RIGHT_SENSOR, INPUT);
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
}
void loop() {
bool left = (digitalRead(LEFT_SENSOR) == LOW); // On line?
bool centre = (digitalRead(CENTRE_SENSOR) == LOW);
bool right = (digitalRead(RIGHT_SENSOR) == LOW);
if (centre && !left && !right) {
// Line is centred - go straight
moveForward(SPEED, SPEED);
} else if (left && !right) {
// Line drifted left - turn left
moveForward(SPEED / 3, SPEED);
} else if (right && !left) {
// Line drifted right - turn right
moveForward(SPEED, SPEED / 3);
} else if (left && right) {
// Intersection or wide line - go straight
moveForward(SPEED, SPEED);
} else {
// Lost the line - stop or search
moveForward(0, 0);
}
}
void moveForward(int leftSpeed, int rightSpeed) {
analogWrite(ENA, leftSpeed);
analogWrite(ENB, rightSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}
For smoother line following, upgrade to a 5-sensor array and use PID control. The 5-sensor setup lets you calculate a precise “line position” value (from -2 to +2), which feeds into a PID algorithm that produces proportional motor speed adjustments instead of simple left/right/straight decisions.
Object Detection Applications
Edge Detection for Robots
Point an IR sensor downward at the floor. When the robot reaches a table edge or stair drop, the sensor loses the floor reflection and outputs HIGH. This prevents the robot from falling off surfaces — essential for table-top robots and Roomba-style cleaners.
Object Counter
Mount an IR sensor at conveyor belt height. Each time an object passes, the sensor triggers. Count the transitions for production counting, visitor counting, or inventory tracking.
Touchless Switch
Use an IR sensor as a proximity trigger for contactless switching. Wave your hand within range to toggle a light, fan, or door mechanism. Useful for kitchen switches (when hands are dirty), public restrooms, and workshops.
Calibration and Troubleshooting
- Adjust the potentiometer with the sensor facing your target surface at the desired detection distance. Turn slowly until the indicator LED just switches — that’s your threshold.
- Ambient light interference: Sunlight contains IR that can overwhelm the sensor’s IR LED. Use indoors or shield the sensor with a tube. For outdoor line followers, use a shroud around each sensor.
- Surface matters: Glossy or reflective floors cause specular reflection that can confuse the sensor. Matte surfaces work best. For line-following tracks, use black electrical tape on white chart paper — this provides the strongest contrast.
- Height calibration: For line followers, mount the sensor 5-15 mm above the surface. Too close and it always detects; too far and it misses the line.
Frequently Asked Questions
How many IR sensors do I need for a line follower robot?
Minimum 2 (left and right of centre — basic left/right correction). Recommended 3 (adds centre detection for straight-line tracking). Ideal 5 (enables PID control and intersection detection). Competition robots often use 7-8 sensors for maximum precision.
Can IR sensors detect transparent objects?
No. Transparent objects (glass, clear plastic, water) pass IR light through them instead of reflecting it. The sensor sees no reflection and reports “no object.” For transparent object detection, use ultrasonic or capacitive sensors instead.
Why does my line follower work indoors but fail outdoors?
Sunlight contains strong IR radiation that saturates the receiver, making it unable to distinguish the sensor’s IR LED reflection. Solutions: (1) Add a shroud/tube around each sensor to block ambient light, (2) increase IR LED power by reducing the series resistor, (3) use sensors with modulated IR (like TSOP receivers) that reject DC ambient light.
Can I use these sensors for long-range detection?
Standard IR obstacle sensors work up to 30 cm. For longer range (1-5m), use Sharp GP2Y0A21 analogue IR sensors (good to 80 cm) or upgrade to ultrasonic (HC-SR04, 400 cm) or LiDAR (TFmini, 1200 cm).
Conclusion
IR obstacle sensors are the simplest, cheapest, and most versatile detection modules for Arduino robotics. A ₹30-50 sensor and 10 lines of code give you obstacle detection, line following, edge detection, or object counting. For competitive line-following robots, invest in a 5-sensor TCRT5000 array and implement PID control — the improvement in speed and accuracy over basic 2-sensor designs is dramatic.
Find IR sensors, sensor arrays, and robotics kits at Zbotic’s sensor collection.
Add comment