Line Follower Robot using Arduino

Line follower Robot is a machine which follows a line, either a black line or white line. Basically there are two types of line follower robots: one is black line follower which follows black line and second is white line follower which follows white line. Line follower actually senses the line and run over it.

 

Concepts of Line Follower

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

Concept of White Line Follower Robot

Concept of Black Line Follower Robot

In this arduino based line follower robot we have used IR Transmitters and IR receivers also called photo diodes. They are used for sending and receiving light. IR transmits infrared lights. When infrared rays falls on white surface, it’s reflected back and catched by photodiodes which generates some voltage changes. When IR light falls on a black surface, light is absorb by the black surface and no rays are reflected back, thus photo diode does not receive any light or rays.

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

 

Circuit Explanation

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

 

Sensor section:

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

 

Control Section:

Arduino Pro Mini is used for controlling whole the process of line follower robot. The outputs of comparators are connected to digital pin number 2 and 3 of arduino. Arduino read these signals and send commands to driver circuit to drive line follower. 

 

Driver section:

Driver section consists motor driver and two DC motors. Motor driver is used for driving motors because arduino does not supply enough voltage and current to motor. So we add a motor driver circuit to get enough voltage and current for motor. Arduino sends commands to this motor driver and then it drive motors.

 

Working of Line Follower Robot using Arduino

Working of line follower is very interesting. Line follower robot senses black line by using sensor and then sends the signal to arduino. Then arduino drives the motor according to sensors' output.

Working of Line Follower Robot using Arduino

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

Working of Arduino Line Follower Robot

If left sensor comes on black line then robot turn left side.

Turning left to line follower robot using arduino

If right sensor sense black line then robot turn right side until both sensor comes at white surface. When white surface comes robot starts moving on forward again.

Turning right to line follower robot

If both sensors comes on black line, robot stops.

Stopping Arduino Line Following Robot

Circuit Diagram

Line Follower Robot using Arduino: Circuit Diagram

Complete circuit diagram for arduino based line follower robot is shown in the above iamge. As you can see output of comparators is directly connected to arduino digital pin number 2 and 3. And motor driver’s input pin 2, 7, 10 and 15 is connected to arduino's digital pin number 4, 5, 6 and 7 respectively. And one motor is connected at output pin of motor driver 3 and 6 and another motor is connected at pin 11 and 14. 

 

Program Explanation

In program, first of all we defined input and output pin, and then in loop we checks inputs and sends output according to inputs to output pin for driving motor. For checking input pin we used “if” statements.

Code for line follower robot

Code for arduino line follower

There are four conditions in this line following robot that we read by using arduino. We have used two sensor namely left sensor and right sensor.

Input

Output

Movement

Of Robot

Left Sensor

Right Sensor

Left Motor

 

Right Motor

LS

RS

LM1

LM2

RM1

RM2

 

0

0

0

0

0

0

Stop

0

1

1

0

0

0

Turn Right

1

0

0

0

1

0

Turn Left

1

1

1

0

1

0

Forward

 

We write program according to the conditions shown in table above.

 

Required Components

Arduino

In our Project we have used a microcontroller to control whole the process of system that is ARDUINO. Arduino is an open source hardware and very useful for project developments. There are many types of arduino like Arduino UNO, arduino mega, arduino pro mini, Lilypad etc. available in the market. Here we have used arduino pro mini in this project as arduino pro mini is small and so breadboard compatible. To burn program we have used FTDI burner.

Arduino pro Mini

 

L293D Motor Driver

L293D is a motor driver IC which has two channels for driving two motors. L293D has two inbuilt Transistor Darlington pair for current amplification and a separate power supply pin for giving external supply to motors.

L293D Motor Driver IC

 

IR Module:

IR Module is sensor circuit which consists IR LED/photodiode pair, potentiometer, LM358, resistors and LED. IR sensor transmits Infrared light and photo diode receives the infrared light.

IR Module

 

Power Supply  

I have added a voltage regulator to get 5 volt for arduino, comparator and motor driver. And a 9 volt battery is used to power the circuit.

Code: 

/*------ Program for Line Follower Robot using Arduino----- */
/*-------definning Inputs------*/
#define LS 2      // left sensor
#define RS 3      // right sensor

/*-------definning Outputs------*/
#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()
{
  if(digitalRead(LS) && digitalRead(RS))     // Move Forward
  {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
  
  if(!(digitalRead(LS)) && digitalRead(RS))     // Turn right
  {
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
  
  if(digitalRead(LS) && !(digitalRead(RS)))     // turn left
  {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }
  
  if(!(digitalRead(LS)) && !(digitalRead(RS)))     // stop
  {
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }
}

Video: 

Comments (33)

  • santhosh kumar's picture
    santhosh kumar

    no

    Sep 13, 2015
  • Rishav Agrahari's picture
    Rishav Agrahari

    Will there be no headder file included in program ? if yes, can u give the complete program.And which software u used to burn program on arduino uno.

    Jan 21, 2016
  • Rudra's picture
    Rudra

    Sir , plz tell how to connect the ir sensor

    Feb 28, 2016
  • Sudhansu's picture
    Sudhansu

    How many pins does your sensor have?
    If 3: you can see they will be marked as follows: VCC, GND and the third pin isOutput. Connect VCC to 5V and GND to Ground and then connect the Output pin to the Analog/Digital pin of Arduino..any way u like it. If you are following this particular code then connect the output of LEFT SENSOR to digital pin 2 of your Arduino and the output of RIGHT SENSOR to digital pin 3 of the Arduino. Hope this helps!!
    In case of 4 pins; the pins are: VCC, GND, Analog(A), Digital(D). In that case if you are following this code then connect the DIGITAL pins of both the sensors in the same way as above,i.e., to digital pins 2 and 3 of the Arduino...
    Hope this helps!!

    Mar 07, 2016
  • Sudhansu's picture
    Sudhansu

    Best description of an LFR n the internet!!! Thanks buddy...

    Mar 07, 2016
  • Devjeet Mandal's picture
    Devjeet Mandal

    Hello, I m not so families with these things. But I wanted to know.. If I have IR module.. Then do I need to put all the resistance, LM358,diode etc as instructed on circuit.

    Mar 10, 2016
  • Khurram Mahmood 's picture
    Khurram Mahmood

    I am using arduino uno, will the same code work and my robot only has 2 motors for the Weels and 2 IR sensors ( 2 receivers and 2 emitters).

    Mar 14, 2016
  • manish pandey's picture
    manish pandey

    This is the perfect platform whr we cn get any information related to arduino..really it is nice1

    Apr 01, 2016
  • Maitry gandhi's picture
    Maitry gandhi

    Can you plz tell me if I am doing pick and place robotic arm along with line follower what should be my code plzzzz I am using arduino mega 2560 and 4 DC motors

    Apr 03, 2016
  • Maitry gandhi's picture
    Maitry gandhi

    Hi I am making pick and place robotic arm along with line follower so can anyone help me in coding section I am using 4 DC motors 2 for base and 1for shoulder 1for wrist and I am using limit switch too plz its too much important for me

    Apr 04, 2016
  • harish's picture
    harish

    hi sir nice project
    i have two ir sensor
    but both a sensor are same
    [i.e] connection of LM358 1st pin output
    but i don't have a 7th pin output
    what can i do sir

    May 25, 2016
  • ashin's picture
    ashin

    its nice.u did a good job. continue your new projects and also share .All things,connecting' s etc are shown very clearly .its very clean.sounds good....

    Jun 07, 2016
  • Pedro's picture
    Pedro

    `LS' was not declared in this scope

    and arduino selects this sentence:
    if(!(digitalRead(LS)) && !(digitalRead(RS))) // stop

    What should i do?
    Thanks.

    Jul 21, 2016
  • Maddy's picture
    Maddy

    Check if you declared the LS properly in the code.

    Aug 20, 2016
  • alejandro's picture
    alejandro

    how can i slow the speed of my motor ? i already test it but i want to slow the speed of my motor what will i do to slow down the speed ?

    Jul 25, 2016
  • Maddy's picture
    Maddy

    You can reduce the driving Voltage by using some voltage regulator like LM317.

    Aug 20, 2016
  • talal's picture
    talal

    produce some delay in program

    Sep 24, 2016
  • KRISHNAPRIYA N's picture
    KRISHNAPRIYA N

    void setup() {
    // put your setup code here, to run once:
    pinMode(5,OUTPUT);
    pinMode(6,OUTPUT);
    pinMode(7,OUTPUT);
    pinMode(8,OUTPUT);
    pinMode(9,INPUT);
    pinMode(10,INPUT);
    }

    void loop() {
    // put your main code here, to run repeatedly:
    int s1=digitalRead(9);
    int s2=digitalRead(10);
    if(s1==HIGH && s2==HIGH)
    {
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(8,LOW);
    }
    else if(s1==HIGH&&s2==LOW)
    {
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    }
    else if(s1==LOW&&s2==HIGH)
    {
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(7,HIGH);
    digitalWrite(8,LOW);
    }
    else
    {
    digitalWrite(5,LOW);
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
    }
    }

    can you please tell me this program is correct or not.

    Aug 11, 2016
  • teena choudhary's picture
    teena choudhary

    your program is correct.....

    Nov 30, 2016
  • soham's picture
    soham

    Hi
    can any one tell me how can we combine two codes means i am having the code for black line and another code for white line i want to combine both the cods so that if while traveling from black line when imediatly white line starts how can i combine the code please help

    Sep 14, 2016
  • Shaff's picture
    Shaff

    Can i know how do you connect the battery ?
    which component that you connect it with ? i try to understand, but i cant find the answer.
    tq

    Oct 07, 2016
  • Abhishek's picture
    Abhishek

    Use a simple 9v Battery, and connect is according to Circuit Diagram.

    Oct 15, 2016
  • Giap's picture
    Giap

    Sir , could you list all the components needed for this project ? thank you .

    Oct 10, 2016
  • isra's picture
    isra

    If you'll be using arduino, what changes to the ckt will be made?

    Oct 18, 2016
  • Annie's picture
    Annie

    How to turn the line follower at exact 90 degree. it would be better if the reply is given the the exact code. thanks.

    Oct 19, 2016
  • Maddy's picture
    Maddy

    It follows Black line, whatever is the path, even 90 degree.

    Oct 27, 2016
  • m faizal iskandar 's picture
    m faizal iskandar

    Basic program and setup for Line Follower Robot

    Nov 12, 2016
  • Jibril's picture
    Jibril

    Please which sensor did you use and where can i buy it

    Dec 06, 2016
  • Abhishek's picture
    Abhishek

    We have used 2 IR sensors or IR modules which mainly consists one IR LED and one Photo diode (Black LED type component). They are available online as well as offline on stores.

    Dec 31, 2016
  • Ikram ul haq's picture
    Ikram ul haq

    Cant upload coding in Arduino fault is showing
    "Arduino: 1.8.0 (Windows 10), Board: "Arduino/Genuino Uno"

    Sketch uses 1178 bytes (3%) of program storage space. Maximum is 32256 bytes.
    Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
    avrdude: ser_open(): can't open device "\\.\COM1": The system cannot find the file specified.

    Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences."

    Please help

    Jan 09, 2017
  • Yuvin Kavisinghe's picture
    Yuvin Kavisinghe

    I have had this problem previously. To fix it I changed the COM port. You can do this by going to tools > port > then select the final port listed.

    Jan 12, 2017

Leave a comment