Line Follower Robot Using Arduino and L298N Module
Line Follower Robot Using Arduino and L298N Module
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.
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
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
COMPONENTS REQUIRED
Arduino Board (UNO)
Car chassis
IR sensor module
12V Battery
On-Off- Switch
Connecting wires
Soldering iron
Solder wire
Software Required
Arduino IDE
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 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);
LEFT();
RIGHT();
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);
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);
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.
IR sensitivity issue?
There is a potentiomenter on the IR sensor module. Adjust with the help of screwdriver as per
your requirement.