Autonomous Line-Following Robotic Vehicle with Dual IR Sensors
Construct an autonomous ground robot capable of optically detecting black track lines on white surfaces and making continuous micro-steering adjustments to follow complex curved paths.
1. Aim of the Project
Project Objective
The goal is to design, calibrate, and program an autonomous wheeled robot that uses optical infrared reflectance sensors to detect high-contrast boundary lines on the floor and autonomously navigate industrial pathways without any human intervention.
2. Interactive 3D Assembly & Circuit Wiring Model
Rotate the 3D model 360 degrees, zoom in/out, disassemble/explode parts to inspect individual hardware layers, toggle realistic circuit wires, and click any component to inspect its engineering specifications.
3. Laboratory Video Masterclass Tutorial
Step-by-step video walkthrough covering breadboard circuit assembly, wiring verification, and testing. Enrolled students and instructors can access video streaming below.
2. Learning Outcomes
Surface Reflectivity Physics
Learn how black surfaces absorb infrared light while white surfaces reflect infrared light back into phototransistors.
Differential Speed Control
Apply proportional motor speeds to smooth out jerky oscillations around sharp 90-degree corners.
Automated State Machines
Implement multi-sensor truth tables (Left On/Right Off, Left Off/Right On, Both Off, Both On) in embedded C++.
3. Technologies Learned
analogWrite())4. Required Components
| Component Name | Quantity | Specification | Interface |
|---|---|---|---|
| Arduino Uno | 1 | ATmega328P microcontroller | GPIO Control |
| IR Tracking Sensor Modules | 2 | TCRT5000 optical reflectance sensors | Digital GPIO (D2, D3) |
| L298N Motor Driver | 1 | Dual H-Bridge Motor Control Board | Pins D5, D6, D9, D10 |
| Geared DC Motors & Chassis | 2 | 3-6V TT gearmotors with wheels & caster | Motor Power |
| 7.4V Battery Pack | 1 | 2x 18650 Li-Ion rechargeable battery case | Power Distribution |
5. Circuit Connection Table
| Sensor / Module Pin | Arduino Pin | Function |
|---|---|---|
| Left IR Sensor (OUT) | Pin D2 | Left track edge detection |
| Right IR Sensor (OUT) | Pin D3 | Right track edge detection |
| L298N IN1 & IN2 | Pins D5, D6 | Left motor direction control |
| L298N IN3 & IN4 | Pins D9, D10 | Right motor direction control |
6. Step-by-Step Tutorial
Mount the IR Sensor Array Underneath
Mount the two TCRT5000 sensor modules under the front bumper pointing downwards, approximately 5mm to 10mm above the floor surface. Space them slightly wider than the width of your black electrical tape track.
Calibrate Comparator Potentiometers
Place one sensor over the white floor and adjust the potentiometer until the onboard indicator LED turns OFF. Move the sensor over the black tape and verify the indicator LED turns ON.
7. Complete Arduino Source Code
/*
* Project: Autonomous Line Following Robot
* Author: ElectronLab STEM Curriculum
* Description: 2-Sensor High-Accuracy Line Tracker
*/
const int LEFT_SENSOR = 2;
const int RIGHT_SENSOR = 3;
// Motor Driver Pins
const int IN1 = 5;
const int IN2 = 6;
const int IN3 = 9;
const int IN4 = 10;
void setup() {
pinMode(LEFT_SENSOR, INPUT);
pinMode(RIGHT_SENSOR, INPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
int leftVal = digitalRead(LEFT_SENSOR);
int rightVal = digitalRead(RIGHT_SENSOR);
// Condition 1: Both sensors on white floor -> Drive straight forward
if (leftVal == LOW && rightVal == LOW) {
forward();
}
// Condition 2: Left sensor on black line -> Turn left to re-center
else if (leftVal == HIGH && rightVal == LOW) {
turnLeft();
}
// Condition 3: Right sensor on black line -> Turn right to re-center
else if (leftVal == LOW && rightVal == HIGH) {
turnRight();
}
// Condition 4: Both sensors on black line (Crossroad / Stop Line) -> Stop
else if (leftVal == HIGH && rightVal == HIGH) {
stopMotors();
}
}
void forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void stopMotors() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
8. Working Principle
The robot operates on continuous closed-loop feedback. When the robot drifts off course, one optical sensor passes over the non-reflective black line. The digital output shifts, signaling the Arduino to halt one wheel and pivot the opposite wheel, pulling the robot back onto the trajectory centerline.
9. Troubleshooting Guide
Robot Over-Shoots Track Curves
The robot is moving too fast for the sensor response time. Lower motor PWM speeds or widen the distance between the dual IR sensor heads.
Turns in Wrong Direction on Black Line
Swap the Left and Right sensor pin assignments in your sketch (Pins 2 and 3).