← Back to Basic Projects

πŸ€– Line Follower Robot

Build a 2-wheel robot that autonomously tracks a black line on white paper using IR sensors and an L298N motor driver.

πŸ“‹ Overview

A line follower robot reads the contrast between a black line and a white surface using infrared sensors and steers its wheels accordingly. It is the classic entry-point into autonomous robotics.

Technical Insight: IR sensors emit 940nm infrared light. White surfaces reflect ~90% of IR, keeping the photodiode output LOW. Black surfaces absorb IR, returning HIGH. By placing two sensors at the front, the robot knows which side has crossed the line and corrects its path in milliseconds.

In simple terms: Left sensor on black AND right on white β†’ the robot has drifted right β†’ steer left (slow left motor). Both on white β†’ straight ahead. Both on black β†’ stop or search. It's reflexive intelligence with only 2 bits of data.

What you'll learn: IR sensor interfacing, motor driver H-bridge direction control, conditional logic for autonomous steering, and robot chassis assembly basics.

Estimated time: 60-90 minutes. Difficulty: ⭐⭐⭐ Intermediate β€” your first fully autonomous robot!

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R3 / Nano5V1Nano fits better on chassis
L298N Motor Driver2A dual H-bridge1
IR Sensor ModulesTCRT5000 or FC-512Left and right sensors
DC Gear Motors6V, 100-200 RPM2With wheels attached
Robot Chassis2WD kit or DIY cardboard1
9V or 12V BatteryWith connector1Motor power supply
Jumper WiresM-M and F-M20

πŸ—ΊοΈ Component Pin Mapping

Line Follower Robot Component Pin Mapping Infographic

πŸ“– Step-by-Step Tutorial

1

Assemble the Chassis

Mount motors on the chassis. Add the castor wheel at the back. Attach the Arduino and L298N securely with screws or double-sided tape.
2

Wire the L298N

Left motor to OUT1/OUT2, right motor to OUT3/OUT4. IN1→pin4, IN2→pin5, IN3→pin6, IN4→pin7. ENA→pin9, ENB→pin10. Power L298N from battery.
3

Mount and Wire IR Sensors

Mount sensors at the front, 5–10mm from the ground, ~4cm apart. Sensor OUT pins β†’ Arduino pin 2 (left) and pin 3 (right). VCC β†’ 5V, GND β†’ GND.
4

Draw a Track

Use 2cm wide black electrical tape on a white foam board. Make gentle curves β€” sharp turns are tricky for beginners.
5

Upload and Calibrate

Upload code. Adjust motor speed constants if the robot veers. Place on track and watch it follow!
πŸ’‘
Keep sensor height between 5–15mm from the floor. Too high and ambient light causes false readings; too low and the sensor clips the ground on uneven surfaces. Use a piece of cardboard to set consistent height during mounting.

πŸ’» Arduino Code

line_follower_robot.ino
INO
// Line Follower Robot β€” Volt X
// 2 IR sensors, L298N motor driver

// Motor Driver Pins
const int ENA = 9,  IN1 = 4,  IN2 = 5; // Left motor
const int ENB = 10, IN3 = 6,  IN4 = 7; // Right motor

// IR Sensor Pins (LOW = black line detected)
const int IR_LEFT  = 2;
const int IR_RIGHT = 3;

const int BASE_SPEED = 200; // 0-255 PWM speed

void setMotors(int lSpeed, int lDir, int rSpeed, int rDir) {
  analogWrite(ENA, lSpeed);
  digitalWrite(IN1, lDir);  digitalWrite(IN2, !lDir);
  analogWrite(ENB, rSpeed);
  digitalWrite(IN3, rDir);  digitalWrite(IN4, !rDir);
}

void setup() {
  pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT);
  pinMode(IR_LEFT, INPUT); pinMode(IR_RIGHT, INPUT);
  Serial.begin(9600);

⭐Reviews & Ratings

β€”0 reviews
5β˜…
0
4β˜…
0
3β˜…
0
2β˜…
0
1β˜…
0
...

Loading reviews...

volt-X / Line Follower Robot β€” Arduino Tutorial