The line follower robot is an automated vehicle that follows a visual black line or path on the surface. This visual line is a path on which the line follower robot moves. It uses a black line on a white surface, or you can also adjust it as a white line on a black surface as per your need.

Beginners and students get their first robotic experience with this type of line follower robot. In this article, we are going to learn how to make a line follower robot using Arduino and the L298N motor driver module.

In industries, line follower robots are used for guiding the automated production process. They are also used in restaurants, military applications, delivery services, hotels, bars, etc. are some of its common applications.

 

How Line Follower Robot works?

The concept of the line follower robot is related to the transmitting and receiving of light. The white colour reflects all the light that falls on it whereas the black colour absorbs all the light.

In this line follower robot, we have used IR transmitters and receivers ( also known as photodiodes). When IR light falls on a white surface, it gets reflected back towards the IR receiver, generating some voltage changes that are analyzed by the Arduino.

When IR light falls on a black surface, it gets absorbed by the black surface, and no rays are reflected back thus, the IR receiver doesn’t receive any rays.

In this project, when the IR sensor senses a white surface, an Arduino gets HIGH as input, and when it senses a black line, an Arduino gets LOW as input. Based on these inputs, an Arduino Uno provides the proper output to control the line follower. 

 

L298N Module

L298N Pinout

IR sensor consists of an Infrared LED and a Photodiode. An IR LED is a special-purpose LED, that emits infrared rays ranging from 700 nm to 1 mm wavelength. Such types of rays are invisible to our eyes. In nutshell, a photodiode or IR Receiver LED detects infrared rays.

Datasheet

Motor controller

L298N, drives 2 DC motors

Operating Voltage

5- 35V

Logic voltage

4.5 – 7 V 

Max current

2A per channel

Voltage Regulator

78M05

Module dimensions

43 x 43 x 28 mm

Junction operating temperature

-25 to 130 o Celsius

  

How IR Sensor Module Works

When we connect the InfraRed sensor module to the 5v power supply. Infrared LED  starts emitting infrared rays. These infrared rays reach to object’s surface and this radiation gets reflected back to the IR receiver. The Photodiode or IR receiver detects the infrared light and produces output accordingly.

 

Components Required

Software Required

  • Arduino IDE

 

Line Follower Robot Circuit Diagram

Line Follower Robot Circuit Diagram

Follow this table in order to make your connections.

L298N driver Pins

Arduino Pins

ENA

jumper

IN1

D9

IN2

D6

IN3

D5

IN4

D3

ENB

jumper

 

Infrared Sensor pins

Arduino pins

Vcc

5v

GND

GND

Right IR sensor OUT

D13

Left IR sensor OUT

D12

 

For L298N motor driver module, motors are connected to the motor terminals of the motor driver module. The motor driver has another 3 terminals, in which one is 12Volt connected to the battery. The GND terminal is connected to the battery’s negative terminal and it is also connected to the Arduino board GND pin and 5v is connected to 5v of the Arduino board.

 

Arduino Code for Line Follower Robot 

#define MOTOR_SPEED 60

int mot1=9;

int mot2=6;

int mot3=5;

int mot4=3;

int left=13;

int right=12;

int Left=0;

int Right=0;

void LEFT (void);

void RIGHT (void);

void STOP (void);

void setup() {

  pinMode(mot1,OUTPUT);

  pinMode(mot2,OUTPUT);

  pinMode(mot3,OUTPUT);

  pinMode(mot4,OUTPUT);

  pinMode(left,INPUT);

  pinMode(right,INPUT);

  digitalWrite(left,HIGH);

  digitalWrite(right,HIGH); 

void loop() { 

analogWrite(mot1,MOTOR_SPEED);

analogWrite(mot2,0);

analogWrite(mot3,MOTOR_SPEED);

analogWrite(mot4,0);

while(1) {

  Left=digitalRead(left);

  Right=digitalRead(right);

  if((Left==0 && Right==1)==1)

  LEFT();

  else if((Right==0 && Left==1)==1)

  RIGHT();

}

}

void LEFT (void) {

   analogWrite(mot3,0);

   analogWrite(mot4,30);

   while(Left==0) {

    Left=digitalRead(left);

    Right=digitalRead(right);

    if(Right==0) {

      int lprev=Left;

      int rprev=Right;

      STOP();

      while(((lprev==Left)&&(rprev==Right))==1) {

         Left=digitalRead(left);

         Right=digitalRead(right);

      }

    }

    analogWrite(mot1,MOTOR_SPEED);

    analogWrite(mot2,0);

   }

   analogWrite(mot3,MOTOR_SPEED);

   analogWrite(mot4,0);

}  

void RIGHT (void) {

   analogWrite(mot1,0);

   analogWrite(mot2,30);  

   while(Right==0) {

    Left=digitalRead(left);

    Right=digitalRead(right);

    if(Left==0) {

      int lprev=Left;

      int rprev=Right;

     STOP();

      while(((lprev==Left)&&(rprev==Right))==1) {

         Left=digitalRead(left);

         Right=digitalRead(right);

      }

    }

    analogWrite(mot3,MOTOR_SPEED);

    analogWrite(mot4,0);

    }

   analogWrite(mot1,MOTOR_SPEED);

   analogWrite(mot2,0);

}

void STOP (void) {

analogWrite(mot1,0);

analogWrite(mot2,0);

analogWrite(mot3,0);

analogWrite(mot4,0);  

} 

 

Troubleshooting

Robot is moving too fast?

For this change value of motor speed in the code. Note that 1 is the minimum value and 255 is the maximum speed.

No power supply?

Try changing your batteries. Ensure that you must supply  12v to the L298 Motor Driver module. A Voltage rating less than this will not work.

Project not working?

Ensure that the circuit you have made is according to the circuit diagram. Check for loose connections. Cross-check for motor connections.

Motors are rotating in opposite direction?

For this, reverse the terminals of the motor connecting the Motor driver module.

IR sensitivity issue?

There is a potentiomenter on the IR sensor module. Adjust with the help of screwdriver as per your requirement.

Leave a comment

Please note, comments must be approved before they are published

Your cart

×
Liquid error (layout/theme line 249): Could not find asset snippets/quantity-breaks-now.liquid