The line following robot
1. What is a Line Follower?
A line follower robot is a small autonomous vehicle that can detect and follow a line — usually a black line on a white surface or white line on a black surface.
It uses IR (Infrared) sensors to detect the line, and Arduino processes the signals to control the motors.
2. Main Components You’ll Need
Arduino Uno / Nano / Mega (Uno is enough for beginners)
IR Sensor Module (2, 3, or more sensors depending on accuracy needed)
Motor Driver Module (L298N, L293D, or similar)
DC Motors (with wheels)
Chassis (robot base)
Battery Pack (7.4V Li-ion or 9V, depending on motors)
Jumper Wires
Black Electrical Tape or painted black line for the track
3. How It Works
1. IR sensors shine infrared light on the floor.
White surface reflects IR light back → sensor output is HIGH.
Black line absorbs IR light → sensor output is LOW.
2. Arduino reads these outputs.
3. Based on sensor readings:
If the middle sensor sees the line → go straight.
If left sensor detects black → turn left.
If right sensor detects black → turn right.
4. The motor driver's changes motor direction/speed accordingly.
4. Basic 2-Sensor Logic
Left Sensor Right Sensor Action
0 0 Stop
1 0 Turn Right
0 1 Turn Left
1 1 Go Forward
Line following robot

5. Arduino program Code
#define LS 2 // Left Sensor
#define RS 3 // Right Sensor
#define LM1 4 // Left Motor +
#define LM2 5 // Left Motor -
#define RM1 6 // Right Motor +
#define RM2 7 // Right Motor -
void setup() {
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}
void loop() {
int leftSensor = digitalRead(LS);
int rightSensor = digitalRead(RS);
if (leftSensor == 1 && rightSensor == 1) {
forward();
}
else if (leftSensor == 0 && rightSensor == 1) {
left();
}
else if (leftSensor == 1 && rightSensor == 0) {
right();
}
else {
stopMotor();
}
}
void forward() {
digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW);
}
void left() {
digitalWrite(LM1, LOW); digitalWrite(LM2, HIGH);
digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW);
}
void right() {
digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW); digitalWrite(RM2, HIGH);
}
void stopMotor() {
digitalWrite(LM1, LOW); digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW); digitalWrite(RM2, LOW);
}
6. Tips for Better Performance
Keep the IR sensors close to the ground (~1 cm gap).
Adjust sensor sensitivity using the potentiometer on the module.
Use more sensors (3, 5, or 8) for smoother turns.
Use PWM speed control to make turns softer instead of jerky.
Comments
Post a Comment