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) – https://www.altium.com/yt/RoboCircuits || $2 for 1-4 Layer PCBs, Get Free SMT Coupons →https://jlcpcb.com/IYB

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

Code



  int vSpeed = 110;        // MAX 255
  int turn_speed = 230;
    // MAX 255 
  int turn_delay = 10;
  
//L293 Connection   
  const
  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
  =A0;
  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);
  pinMode(motorB2,
  OUTPUT);

  Serial.begin(9600);

  delay(3000);
  
}

void
  loop() {

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

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

  digitalWrite (motorA1,LOW);

  digitalWrite(motorA2,HIGH);                       
  digitalWrite (motorB1,LOW);

  digitalWrite(motorB2,HIGH);

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

  digitalWrite(motorA2,LOW);                       
  digitalWrite (motorB1,HIGH);

  digitalWrite(motorB2,LOW);

  analogWrite (motorAspeed, turn_speed);

  analogWrite (motorBspeed, vSpeed);

  delay(turn_delay);
  }

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


  digitalWrite (motorA2,LOW);
  digitalWrite(motorA1,HIGH);                       

  digitalWrite (motorB2,HIGH);
  digitalWrite(motorB1,LOW);

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

  delay(turn_delay);

  
  }

if(right_sensor_state < 500 && left_sensor_state < 500)
{ 

  Serial.println("stop");
  
  analogWrite (motorAspeed, 0);
  analogWrite
  (motorBspeed, 0);
  
  }

}

Facebook – https://facebook.com/Robocircuits

Instagram – https://Instagram.com/Robocircuits

Twitter – https://Twitter.com/Robocircuits

7 thoughts on “How to make Line Follower Robot with Arduino”

  1. After I originally left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I recieve four emails with the exact same comment. Is there a way you can remove me from that service? Many thanks!

    Reply
  2. May I simply say what a comfort to discover someone that really knows what they are talking about on the web. You definitely know how to bring a problem to light and make it important. More people should read this and understand this side of the story. I was surprised you arent more popular since you definitely have the gift.

    Reply
  3. May I simply say what a comfort to discover somebody who genuinely knows what they are talking about over the internet. You actually understand how to bring a problem to light and make it important. More people ought to check this out and understand this side of the story. I cant believe you arent more popular because you surely possess the gift.

    Reply

Leave a Comment