You are on page 1of 7

instructables

How to Make Line Follower Robot Using Arduino

by Aarav G

In this instructable, I will teach you how to make a and on the basis of input received from the sensors,
line follower robot using Arduino, which is a very the Arduino will direct the motors to move with the
common microcontroller board. The robot will use help of a motor shield.
two infrared proximity sensors to detect the line

https://www.youtube.com/watch?v=QAkmBtT7aLc

How to Make Line Follower Robot Using Arduino: Page 1


Step 1: The Working

So there will be infrared proximity sensors placed Case 2:-


on either side at the front of the robot. There are four
possible sensor outcomes:- In this case, only the left sensor detects the line
which means that the car requires to turn in the left
Case 1:- direction. The left motor rotates backward and the
right motor rotates forward. As a result, the car turns
In this case, both the sensors don't detect the line. left.
Both the motors rotate forward. As a result, the car
moves forward. Case 3:-

In this case, only the right sensor detects the line In this case, both the sensors detect the line. This
which means that the car requires to turn in the means that the end has come. Both the motors stop
right direction. The left motor rotates forward and rotating. As a result, the car stops.
the right motor rotates backward. As a result, the car
turns right. That is the working structure of our robot...

Case 4:-

How to Make Line Follower Robot Using Arduino: Page 2


Step 2: Parts Required

The parts required to build the robot are as follows:

Chassis (including motors and wheels )


Arduino Uno r3
L293D Motor Shield
IR Proximity Sensors (pair)
Jumper Wires
Switch
4AA Battery Holder

Tools required:-

Soldering Iron
Hot Glue Gun
Screw Driver

Gather these parts and be ready for the next step ...

Step 3: Assemble the Chassis

Now, assemble your robot body. Everyone may have Also, attach the proximity sensors at the front on
a different chassis. So assemble your chassis either side, facing down. Make sure that they are
accordingly. Most of the chassis come with an attached at the corners...
instruction manual and even mine came with it so
have a look at it and build your chassis accordingly. Attach the switch too...
Then, attach the components to the chassis.
Arduino, with the motor shield attached to it and Solder wires to the motors and also switch and
also the battery holder must be fixed on the keep ready...
chassis.

How to Make Line Follower Robot Using Arduino: Page 3


Step 4: Main Connections

Now do the connections as per the diagram above...

Left Sensor>>Arduino:-

Vcc>>5v
Gnd>>Gnd
Out>>A4

Right Sensor>>Arduino:-

Vcc>>5v
Gnd>>Gnd
Out>>A5

Connect the motors to the motor shield and plug the motor shield onto the Arduino board. Connect the
battery holder to the shield through a switch. That's it for the connections, let's move on to the next step...

How to Make Line Follower Robot Using Arduino: Page 4


Step 5: Arduino Code

Now its time for the main thing- coding our robot...

Download my Arduino code file or write up your own code to get done...

Download
https://www.instructables.com/ORIG/FXQ/VHSR/JGGTIBCG/FXQVHSRJGGTIBCG.ino

I made this project but I decided to use my own chassis and board but the coding would be the
same. I had to alter some parts of the code it could work with my robot but otherwise, it worked
well.

Awesome work...

Hey i am going to make this for a student project and I was wondering do I only need the power
source of the 4 AA batteries? Or do I need something to power the board as well?
The 4 AA batteries can be used to power the board and the motors will be powered as well by
them. So using 4 AA batteries are enough as the motor shield can provide the motors with enough
current so you just have to connect the battery wires to the arduino power pins
Ok that makes more sense. Thanks for the help!!!

Thanks a lot...!!! I made it. There was some changes needed in the code that's it.

How to Make Line Follower Robot Using Arduino: Page 5


the code cannot be downloaded.
How can I get it?
Please, I need it for a student project
Thanx
////////////////////////////////////////////////////////
// LinoBot v1.0 //
// By Aarav Garg //
////////////////////////////////////////////////////////

//I have added the possibilities of testing


//The values of analogRead could be changed for trouble shooting

//including the libraries


#include <AFMotor.h>

//defining pins and variables


#define lefts A4
#define rights A5

//defining motors
AF_DCMotor motor1(4, MOTOR12_8KHZ);
AF_DCMotor motor2(3, MOTOR12_8KHZ);
/*
AF_DCMotor motor1(3, MOTOR12_8KHZ);
AF_DCMotor motor2(4, MOTOR12_8KHZ);
*/

void setup() {
//setting the speed of motors
motor1.setSpeed(200);
motor2.setSpeed(200);
//declaring pin types
pinMode(lefts,INPUT);
pinMode(rights,INPUT);
//begin serial communication
Serial.begin(9600);
}

void loop(){
//printing values of the sensors to the serial monitor
Serial.println(analogRead(lefts));
Serial.println(analogRead(rights));
//line detected by both
if(analogRead(lefts)<=400 && analogRead(rights)<=400){
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
}
//line detected by left sensor
else if(analogRead(lefts)<=400 && !analogRead(rights)<=400){
//turn left
motor1.run(BACKWARD);
motor2.run(FORWARD);
How to Make Line Follower Robot Using Arduino: Page 6
/*
motor1.run(RELEASE);
motor2.run(FORWARD);
*/
}
//line detected by right sensor
else if(!analogRead(lefts)<=400 && analogRead(rights)<=400){
//turn right
motor1.run(FORWARD);
motor2.run(BACKWARD);
/*
motor1.run(FORWARD);
motor2.run(RELEASE);
*/
}
//line detected by none
else if(!analogRead(lefts)<=400 && !analogRead(rights)<=400){
//stop
motor1.run(FORWARD);
motor2.run(FORWARD);
/*
motor1.run(BACKWARD);
motor2.run(BACKWARD);
*/
}
}

Thank you man. Very nice of you. Good job. Great

I have made all connections and coding but the left sensor is unable to rotate the motors, it reacts
when black colour comes but it's unable to send signal to the motor and act accordingly, can u pls
tell me where is the problem.
You need to change the code because your sensors are of complement type. Means they give
signal 1 when there is black line.
Try checking sensor values using the serial monitor.

The arduino microcontroller is used to control the moment of the robots. I was attended the ipt in
trichy, it is very helpful for my projects to do my self.
For more details:

https://inplanttrainingintrichy.co.in

How to Make Line Follower Robot Using Arduino: Page 7

You might also like