How to Make Line Follower Robot Using Arduino

35,377

13

20

About: I am a student...

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

Step 1: The Working

So there will be infrared proximity sensors placed on either side at the front of the robot. There are four possible sensor outcomes:-

Case 1:-

In this case, both the sensors don't detect the line. Both the motors rotate forward. As a result, the car moves forward.

Case 2:-

In this case, only the left sensor detects the line which means that the car requires to turn in the left direction. The left motor rotates backward and the right motor rotates forward. As a result, the car turns left.

Case 3:-

In this case, only the right sensor detects the line which means that the car requires to turn in the right direction. The left motor rotates forward and the right motor rotates backward. As a result, the car turns right.

Case 4:-

In this case, both the sensors detect the line. This means that the end has come. Both the motors stop rotating. As a result, the car stops.

That is the working structure of our robot...

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 a different chassis. So assemble your chassis accordingly. Most of the chassis come with an instruction manual and even mine came with it so have a look at it and build your chassis accordingly. Then, attach the components to the chassis. Arduino, with the motor shield attached to it and also the battery holder must be fixed on the chassis.

Also, attach the proximity sensors at the front on either side, facing down. Make sure that they are attached at the corners...

Attach the switch too...

Solder wires to the motors and also switch and keep ready...

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...

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...

Share

Recommendations

  • Tape Contest

    Tape Contest
  • Arduino Contest 2019

    Arduino Contest 2019
  • Trash to Treasure

    Trash to Treasure

20 Discussions

0
None
aaron.herrera

19 days ago

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?

2 replies
0
None
Aarav Gaaron.herrera

Reply 19 days ago

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

0
None
MayankP37

Question 26 days ago on Step 5

How to determine the position and sensitivity of IR Sensor. And the width of the black line ??!!

2 answers
0
None
Aarav GMayankP37

Answer 19 days ago

Well see keep the width of the line about 5 to 6 cm and place your sensors at the left and right tips of the chassis on the front of the robot. Regarding g sensitivity, you can adjust it usi g the potentiometer present on the ir sensors until they give the needed output...

0
None
MayankP37Aarav G

Reply 18 days ago

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

0
None
Aarav GThiệnH12

Best Answer 2 months ago

You can get the chassis at Amazon of Flipkart.

0
None
wexler

2 months ago

the code cannot be downloaded.
How can I get it?
Please, I need it for a student project
Thanx

2 replies
0
None
Aarav Gwexler

Reply 2 months ago

////////////////////////////////////////////////////////
// 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);
/*
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);
*/
}
}

0
None
wexlerAarav G

Reply 2 months ago

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

0
None
vidhyotha

5 months ago on Step 5

HELLO WHEN I TRIED TO UPLOAD THE CODE TO MU ARDUINO UNO BOARD
ITS TELLING ERROR: AFMotor.h directory is not found
can yu please help me in this because when i saw your sight i was inspired to do this project in my school and i have to exhibit it by this month end and i really need your help.
please its my sincere request from my side to rectify this problem

2 answers
1
None
Roshanijaz1vidhyotha

Answer 3 months ago

You need to download Ahmotor library in order to run or upload the code.

0
None
Aarav Gvidhyotha

Best Answer 5 months ago

You will have to download the afmotor library first in order to successfully run the program. You can get it on github.

0
None
VrushankM

5 months ago

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.

2 replies
0
None
Roshanijaz1VrushankM

Reply 3 months ago

You need to change the code because your sensors are of complement type. Means they give signal 1 when there is black line.

0
None
Aarav GVrushankM

Reply 5 months ago

Try checking sensor values using the serial monitor.

0
None
shubham12297

Question 6 months ago on Step 5

After compiling of your program
It generates error and says some file is missing

1 answer
0
None
Aarav Gshubham12297

Answer 5 months ago

Author: You should first install the necessary libraries and add them to your sketch. You can get information on how to do this at the arduino forum.