Introduction: Line Follower Robot Aka FOLO-SAUR
A line-following robot is a type of autonomous robotic vehicle that has the ability to detect and follow a specific path or line that is usually visible on the ground. Most commonly, this path is a black line on a white surface, but it can also be a white line on a black surface depending on the configuration of the sensors and design. The robot follows the line without any manual guidance or external control. It uses infrared (IR) sensors to differentiate between the line and the background surface. These sensors detect the contrast between black and white surfaces by sensing the amount of infrared light reflected back to them.
The concept of line-following robots is one of the most basic and widely implemented projects in robotics, especially in educational and research environments. Despite being relatively simple in terms of hardware and software, the underlying principles introduce students and developers to key areas such as autonomous navigation, real-time decision making, and sensor-based control systems.
The robot works by continuously reading data from multiple IR sensors placed at the front of the chassis. These readings are processed by a microcontroller, such as an Arduino Uno, which decides the direction of movement based on which sensors detect the line. The microcontroller then sends appropriate signals to a motor driver, which in turn controls the direction and speed of the robot’s wheels using DC motors.
Attachments
Supplies
Arduino Uno : Main micro-controller board used to control the robot
L298N Motor Driver Module : Used to control the direction and speed of DC motors
5-Channel IR Sensor Module : Detects black or white (light and dark tbh) surface under each sensor
2 Motors (DC Geared Motor) : Drives the wheels
2 Wheels : Attached to the motors
Chassis Frame : Holds all components together (you can diy it like i did )
Battery Pack (9V or 12V) : Provides power to the motors and Arduino
Jumper Wires : For connections between components
Breadboard (optional) : For prototyping and testing connections
Step 1: Pin Configuration
Pin Configuration:
- IR Sensors (A0 - A4): Connected to analogue pins A0 through A4 on Arduino
- Motors:
- Motor 1 (Right): Controlled using pins 4 and 5; speed via pin 9
- Motor 2 (Left): Controlled using pins 2 and 3; speed via pin 10
- Power Supply:
- Arduino is powered through USB or a 9V battery
- Motor driver powered using a separate battery pack (9V/12V)
Each IR sensor has three connections: VCC (power), GND (ground), and signal (S1–S5). These signal pins go into the Arduino and are used to determine the colour beneath the sensor.
I got this from exploreembedded.com . Check them out.
Step 2: Working Principle
The fundamental working principle of a line-following robot revolves around its ability to detect and react to visual cues on the ground using infrared (IR) sensors. The robot continuously scans the surface beneath it using a set of strategically placed IR sensors, and then makes decisions about its movement based on the pattern of sensor readings.
Infrared Sensor Behaviour
IR sensors operate on the principle of light reflection:
- White surfaces reflect infrared light strongly. When an IR sensor is placed over a white surface, it receives a significant amount of reflected infrared light, and the sensor output is HIGH (1).
- Black surfaces absorb most of the infrared light. When a sensor is over a black surface (such as the guiding line), very little light is reflected back, and the sensor outputs a LOW (0).
By placing multiple IR sensors side-by-side (typically 5 sensors), the robot gains a field of vision that can detect where the line is in relation to the robot’s current position.
Step 3: Assemble the Chassis
- Mount the two DC motors on the chassis.
- Attach the wheels to the motors, and add a caster wheel for balance.
- Fix the battery holder and motor driver on the chassis.
Step 4: Place the Sensors
Attach IR sensors at the front, facing the ground.
Keep them close to the line (about 1–2 cm above the surface).
If using 2 sensors → one left, one right of the line.
If using 3–5 sensors → arrange them in a row for better accuracy.
Step 5: Connect the Circuit
Connect motors → Motor Driver → Microcontroller.
Connect IR sensors → Microcontroller digital/analog pins.
Power the motor driver and microcontroller from the battery.
Make sure grounds are connected together.
Step 6: Upload the Code...
#define m1 4 //Right Motor MA1
#define m2 5 //Right Motor MA2
#define m3 2 //Left Motor MB1
#define m4 3 //Left Motor MB2
#define e1 9 //Right Motor Enable Pin EA
#define e2 10 //Left Motor Enable Pin EB
//**********5 Channel IR Sensor Connection**********//
#define ir1 A0
#define ir2 A1
#define ir3 A2
#define ir4 A3
#define ir5 A4
//*************************************************//
void setup() {
pinMode(m1, OUTPUT);
pinMode(m2, OUTPUT);
pinMode(m3, OUTPUT);
pinMode(m4, OUTPUT);
pinMode(e1, OUTPUT);
pinMode(e2, OUTPUT);
pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(ir3, INPUT);
pinMode(ir4, INPUT);
pinMode(ir5, INPUT);
}
void loop() {
//Reading Sensor Values
int s1 = digitalRead(ir1); //Left Most Sensor
int s2 = digitalRead(ir2); //Left Sensor
int s3 = digitalRead(ir3); //Middle Sensor
int s4 = digitalRead(ir4); //Right Sensor
int s5 = digitalRead(ir5); //Right Most Sensor
//if only middle sensor detects black line
if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going forward with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
digitalWrite(m3, HIGH);
digitalWrite(m4, LOW);
}
//if only left sensor detects black line
if((s1 == 1) && (s2 == 0) && (s3 == 1) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
digitalWrite(m3, LOW);
digitalWrite(m4, LOW);
}
//if only left most sensor detects black line
if((s1 == 0) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
digitalWrite(m3, LOW);
digitalWrite(m4, HIGH);
}
//if only right sensor detects black line
if((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 0) && (s5 == 1))
{
//going left with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
digitalWrite(m3, HIGH);
digitalWrite(m4, LOW);
}
//if only right most sensor detects black line
if((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 0))
{
//going left with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, LOW);
digitalWrite(m2, HIGH);
digitalWrite(m3, HIGH);
digitalWrite(m4, LOW);
}
//if middle and right sensor detects black line
if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 1))
{
//going left with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
digitalWrite(m3, HIGH);
digitalWrite(m4, LOW);
}
//if middle and left sensor detects black line
if((s1 == 1) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
digitalWrite(m3, LOW);
digitalWrite(m4, LOW);
}
//if middle, left and left most sensor detects black line
if((s1 == 0) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, HIGH);
digitalWrite(m2, LOW);
digitalWrite(m3, LOW);
digitalWrite(m4, LOW);
}
//if middle, right and right most sensor detects black line
if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 0))
{
//going left with full speed
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255
analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
digitalWrite(m3, HIGH);
digitalWrite(m4, LOW);
}
//if all sensors are on a black line
if((s1 == 0) && (s2 == 0) && (s3 == 0) && (s4 == 0) && (s5 == 0))
{
//stop
digitalWrite(m1, LOW);
digitalWrite(m2, LOW);
digitalWrite(m3, LOW);
digitalWrite(m4, LOW);
}
}
code is taken from a github repo. Since i was having issues with my original code i used it...



