How to make Line Follower Robot with Arduino

A line follower robot is a robot that follows a certain path controlled by a feedback mechanism. It uses Arduino as a controller. You can make it yourself at home.

Get Altium (One Month Free) – || $2 for 1-4 Layer PCBs, Get Free SMT Coupons →

A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact. A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the area or return signal.

Concepts of Line Follower

The concept of working as a line follower is related to light. We use here the behavior of light on a black-and-white surface. When light fall on a white surface it is almost fully reflected and in the case of a black surface light is completely absorbed. This behavior of light is used in building a line follower robot.

IR sensor arduino
IR light is reflected by the White surface and detected by IR RX

IR sensor arduino
IR light absorbed by the black surface

In this Arduino-based line follower robot, we used IR Transmitters and receivers, also called photodiodes. They are used for sending and receiving light. IR transmits infrared lights. When infrared rays fall on a white surface, they are reflected and cached by photodiodes which generate voltage changes. When IR light falls on a black surface, light is absorbed by the black surface and no rays are reflected, thus photodiode does not receive any light or glow.

Here in this Arduino line follower robot when the sensor senses the white surface then Arduino gets 1 as input and when senses the black line Arduino gets 0 as input.

Circuit Explanation

The whole Arduino line follower robot can be divided into 3 sections: sensor section, control section, and driver section.

Sensor section:

This section contains IR diodes, potentiometers, Comparator (Op-Amp), and LEDs. Potentiometer is used for setting reference voltage at the comparator’s one terminal and IR sensors are used to sense the line and provide a change in voltage at the comparator’s second terminal. Then comparator compares both voltages and generates a digital signal at the output. Here in this line follower circuit, we have used two comparators for two sensors. LM 358 is used as a comparator. LM358 has inbuilt two low-noise Op-amps.

Working of Line Follower Robot using Arduino

Working with line followers is very interesting. Line follower robot senses black line by using a sensor and then sends the signal to Arduino. Then Arduino drives the motor according to the sensors’ output.

line follower robot Arduino
Block diagram of Line Follower

Here in this project, we are using two IR sensor modules namely the left sensor and the right sensor. When both the left and right sensor senses white the robot moves forward.

line follower robot Arduino
Both sensors on white

If the left sensor comes on a black line then the robot turns to the left side.

line follower robot Arduino
Left sensor to the black

If the right sensor senses the black line then the robot turns the right side until both sensors come to a white surface. When the white surface comes robot starts moving on forward again.

line follower robot Arduino
The right sensor on black

If both sensors come on a black line, the robot stops.

line follower robot Arduino
both sensors on black

Also, check out another article on How to make an IoT Door Lock

Circuit Diagram


  int vSpeed = 110;        // MAX 255
  int turn_speed = 230;
    // MAX 255 
  int turn_delay = 10;
//L293 Connection   
  int motorA1      = 8;  
  const int motorA2      = 10; 
  const int motorAspeed
  = 9;
  const int motorB1      = 12; 
  const int motorB2      = 13; 

  const int motorBspeed  = 11;

//Sensor Connection
  const int left_sensor_pin
  const int right_sensor_pin =A1;

  int left_sensor_state;

  int right_sensor_state;

void setup() {
  pinMode(motorA1, OUTPUT);

  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);



  loop() {

left_sensor_state = analogRead(left_sensor_pin);
  = analogRead(right_sensor_pin);

if(right_sensor_state > 500 && left_sensor_state
  < 500)
  Serial.println("turning right");

  digitalWrite (motorA1,LOW);

  digitalWrite (motorB1,LOW);


  analogWrite (motorAspeed, vSpeed);
  (motorBspeed, turn_speed);
if(right_sensor_state < 500 && left_sensor_state
  > 500)
  Serial.println("turning left");
  digitalWrite (motorA1,HIGH);

  digitalWrite (motorB1,HIGH);


  analogWrite (motorAspeed, turn_speed);

  analogWrite (motorBspeed, vSpeed);


  > 500 && left_sensor_state > 500)
  Serial.println("going forward");

  digitalWrite (motorA2,LOW);

  digitalWrite (motorB2,HIGH);

  (motorAspeed, vSpeed);
  analogWrite (motorBspeed, vSpeed);



if(right_sensor_state < 500 && left_sensor_state < 500)

  analogWrite (motorAspeed, 0);
  (motorBspeed, 0);


Facebook –

Instagram –

Twitter –

1 thought on “How to make Line Follower Robot with Arduino”

Leave a Comment