A Line Follower Robot, as the name suggests, is an automated guided vehicle, which follow a visual line embedded on the floor or ceiling. Usually, the visual line is the path in which the line follower robot goes and it will be a black line on a white surface but the other way (white line on a black surface) is also possible. Certain advanced Line Follower Robots use invisible magnetic field as their paths.
Large line follower robots are usually used in industries for assisting the automated production process. They are also used in military applications, human assistance purpose, delivery services etc.
Outline
ToggleHow To Make Arduino Line Follower Robot?
Line follower Robot is one of the first robots that beginners and students would get their first robotic experience with. In this project, we have designed a simple Line Follower Robot using Arduino and some other components.
Circuit Diagram
Components Required
- Arduino UNO (or Arduino Nano) [Buy Here]
- L293D Motor Driver IC [Buy Here]
- Geared Motors x 2
- Robot Chassis
- IR Sensor Module x 2
- Black Tape (Electrical Insulation Tape)
- Connecting Wires
- Power supply
- Battery Connector
- Battery Holder
Note: We have used a prebuilt IR Sensor Module that consists of an IR LED and a Photo Diode. If you do not have this, we have explained how to build one yourself.
Block Diagram of the Project
The line follower robot built in this project is divided in to 4 blocks. The following image shows the block diagram for line follower robot.
Block Diagram Description
Sensors (IR Sensor): We have used IR Sensor Module as the line detecting sensor for the project. It consists of an IR LED and a Photo diode and some other components like comparator, LED etc.
As mentioned earlier, we have used a pre – assembled IR Sensor. In case you do not have one, you can make your own sensor using the following circuit.
The working of the IR Sensor and its scope in this project will be explained in the actual working of the Line Follower Robot.
Controller (Arduino UNO): Arduino UNO is the main controller in the project. The data from the sensors (IR Sensors) will be given to Arduino and it gives corresponding signals to the Motor Driver IC.
Motor Driver (L293D): L293D Motor Driver IC is used in this project to drive the motors of the robot. It receives signals from Arduino based on the information from the IR Sensors.
Note: The power supply to the motors must be given from the motor driver IC. Hence, choose the appropriate power supply which is sufficient for all the components including the motors.
Motors (Geared Motors): We have used two geared motors at the rear of the line follower robot. These motors provide more torque than normal motors and can be used for carrying some load as well.
Working of Arduino Line Follower Robot
In this project, we have designed an Arduino based Line Follower Robot. The working of the project is pretty simple: detect the black line on the surface and move along that line. The detailed working is explained here.
As mentioned in the block diagram, we need sensors to detect the line. For line detection logic, we used two IR Sensors, which consists of IR LED and Photodiode. They are placed in a reflective way i.e. side – by – side so that whenever they come in to proximity of a reflective surface, the light emitted by IR LED will be detected by Photo diode.
The following image shows the working of a typical IR Sensor (IR LED – Photodiode pair) in front of a light coloured surface and a black surface. As the reflectance of the light coloured surface is high, the infrared light emitted by IR LED will be maximum reflected and will be detected by the Photodiode.
In case of black surface, which has a low reflectance, the light gets completely absorbed by the black surface and doesn’t reach the photodiode.
Using the same principle, we will setup the IR Sensors on the Line Follower Robot such that the two IR Sensors are on the either side of the black line on the floor. The setup is shown below.
When the robot moves forward, both the sensors wait for the line to be detected. For example, if the IR Sensor 1 in the above image detects the black line, it means that there is a right curve (or turn) ahead.
Arduino UNO detects this change and sends signal to motor driver accordingly. In order to turn right, the motor on the right side of the robot is slowed down using PWM, while the motor on the left side is run at normal speed.
Similarly, when the IR Sensor 2 detects the black line first, it means that there is a left curve ahead and the robot has to turn left. For the robot to turn left, the motor on the left side of the robot is slowed down (or can be stopped completely or can be rotated in opposite direction) and the motor on the right side is run at normal speed.
Arduino UNO continuously monitors the data from both the sensors and turns the robot as per the line detected by them.
Code
Note:
- In order to increase the efficiency of black line detection, number of sensors can be increased. An array of sensors will be more accurate than just two sensors.
- In this project (where two sensors are used), the positioning of the sensors is very important. The width of the black line plays a major role in the placement of the sensors.
- The sensor to detect the line can also be constructed using an LED and LDR pair.
Applications of Line Follower Robot
- Line follower Robots are commonly used for automation process in industries, military applications and consumer applications.
- They are very useful as they can work without any supervision i.e. they work as automatic guided vehicles.
- With additional features like obstacle avoidance and other security measures, line follower robots can be used in driver less cars.
Construction and Output Video
This is the starter kit that has come into the existence when a motion of the robot is given high priority. It follows the visual line path and some advanced line follower robots uses an invisible magnetic field as their paths.
As you are aware of robot applications in military, industries and domestic purposes that are in great demand. We offered the Arduino Robot Kits that satisfies all your desires. Have a look at these Arduino robot kits that has a wide range of applications and comes at very low prices.
If you have any doubts, please share with us in the comment section given below. We are very happy to respond quickly.
Recommended read:
78 Responses
very helpful article for newbie ! You make things easy to understand
In the code, left and right are set as input pins, yet you are writing into them in the next line. Is that possible ? If yes, why ?
Hi, If you observe carefully, first left and right are actual pins of Arduino (13 and 12) and they are in lower case. The second Left and Right are just integer variables, with L and R are in upper case, in corresponding words.
Hi, could u please explain me how can we stop this line following robot using in the desired location ?
Hi, We are stopping the robot if both the sensors detect a black line (at the same time). You can notice in the video that at the end of the path, we have put a thick line across the path. If you want to stop your robot at any desired location (with in the path), you might go with a GPS system. A remote controlled robot will be a good idea.
From where can I buy the particular motor driver shield?
You can get the motor shield from online sellers like Amazon, AliExpress or DealeXtreme.
will it make a difference if i connect the IR pins to the analog pins on arduino rather than connecting them to PWM pins?
Hiiii….I want to know that what is the IC name of Aurdino UNO as we purchased from the shop
It is ATMEGA328.
Can u send me white line follower robot using aurdino (Coding) plz send if u can.
which two wires you connect in motor ic
i want a line follower with obstacle detector that is it must me stopped when an object is detected and when the objects removed it will continue the line plzz help me with code and hardware connection
you might use a ultrasonic sensor for that.
can i use ultrasonic and ir sensor together in a line follower robot
Yes, you can use . If your going to do that pls see YouTube videos .
can i use a l298n motor driver?
Yes. Definitely. Check out the pin configuration.
Which power supply should I use?
Can i have the code for 4 sensor line follower
Hey man, thanks for this post but could you link me the motors and IR sensors you used? That would be helpful. I’m going to build off of this template and I would like to know the parts to use since there are just so dag on many.
Thanks!
Hi,
For that Chassis wheels, what is the name of that object which you connected to wheels not the motors, the other side
Hello, do you use a special Library ?
if yes, could you help me.
Hi, followed your tutorial but my motors spin when the sensors are in black surface but stop when they’re in white. The video show that the motors stop when it detects blacks on both sensors. Essentially, i have a white line follower. What part of your code should I change. I’m stumped. Thanks for the tutorial.
how to change the rotation from clockwise into anticlockwise in code
about motors
I am following this guide ….but for some reason the motors directly start spinning without even connecting the ir sensors
how can i make my bot remember the correct path so that if i make it move again on the same line it follows only the right direction and not take the wrong turns like it will take in the first run.
What is max RPM of motor that i can use in this drive
Can give the circuit diagram of the l293d motor driver, because of it have something different from other l293d drivers
how can i increase the speed of robot so it will run fast?
On the video the L293D is on a board. Where can I get the diagram of the board configuration where the L293D is located?
I want to write a programme of line following robot using mega aurdino
Using four motors
Give me suggestion
hi what pin should i put when i like to add 3 more sensor on the circuit
Can I use stepper motors with this tutorial? If so would I be able to use the ULN2003 Stepper Motor Driver Board 1PC as the motor driver board? I am completely new at Arduino so sorry if these questions are obvious
Supply to Motors is given through the Motor Driver. In case of L293D, Vcc2 (Pin 8) is the motor supply pin. Depending on the voltage rating of your motor, connect the positive terminal of the Motor Power Supply to this pin. Connect the negative terminal to GND.
The codings are showing some errors, os that the whole coding or some part is missing?
Hi,
The code is tested multiple times. It is working perfectly fine.
it is moving on the black surface n stoping on white so basically it is a white line follower i want to change it .how do i?
i realise that it’s really much helpfull for me as a beginer.
What was that last thing that you did ?
Connection of black part of arduino with the motor driver?
That i could not understand…..please help me…..
The program is not getting installed in the arduino board …Its telling that problem uploading to the arduino board….
what should i do???
It’s an request please help me!!!!!!!
That was just a male to female header converter (so that both Arduino and Motor Driver has female headers).
Hello
I am using 4 DC motors and a kind of motor drive kit which gets assembled directly on the Arduino board without any wire. I do not work, it makes no reaction.
your program shows four motors, while your video shows two motors.
Only two motors in the program. mot1, mot2, mot3 and mot4 are inputs of the Motor Driver (two inputs for one motor).
Hi, i have made this robot with 4 and 5 ir sensors. But my robot is not efficent to move fast while following the line. My hardware works fine but my code’s logic is not efficient. Can you share any code using 4 or 5 sensors which can make robot to move fast.
Thanks.
Could I replace the ir with ultrasonic?
i have made a line follower with the help of your article. But in my case i have to keep both the IR on the black line then only the motor rotates . And second thing , the motor wont stop on the perpendicular lines, it only stops when on bright colors, And it wont even make a turn, i think that’s because of motor speed, so how to adjust the motor speed ?
does this program work when there is an interception in the line? can the speed of the robot can be adjust?
On the video the L293D is on a board. Where can I get the diagram of the board configuration where the L293D is located?
Or is the board not that necessary ?
Where did you buy the chassis. I am having trouble finding one similar to this.
I have bought it from a local electronics store. You can find one (a similar one, if not an exact one) in Amazon or ebay.
Is battery is connected to aurdino or motors?
To both.
You are giving
supply to Arduino from the motor driver…is it right…?
hi. can someone correct my code
// Connect the motor driver GND pin to the Arduino ground pin
// Connect eh motor driver +12V pin to the Arduino Vin pin
// connect motor controller pins to Arduino digital pins
// Left Motor
int enLeft = 5;
int in1 = 6;
int in2 = 7;
// Right Motor
int in3 = 8;
int in4 = 9;
int enRight = 10;
//LightSensor
int LightRight = 4;
int LightLeft = 3;
//Ultasound sensor
int echoPin = 11;
int trigPin =12;
double RANGE();
void goMotors(int, int, int, int);
void setup()
{
// set all the motor control pins to outputs
pinMode(enLeft, OUTPUT);
pinMode(enRight, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
//The Light Sensor is on if it can sense the reflected light
//If the background is black there is no reflection thus it is off
//When the background is white there is a reflection this it is on.
if(digitalRead(LightRight)==LOW && digitalRead(LightLeft)==LOW)
{
//If there is black line stop
goMotors(enLeft,in1,in2,00);
goMotors(enRight,in3,in4,00);
}
else if (digitalRead(LightRight)==LOW && digitalRead(LightLeft)==HIGH)
{
//If there is no black line stop
goMotors(enLeft,in1,in2,-100);
goMotors(enRight,in3,in4,00);
}
else if (digitalRead(LightRight)==HIGH && digitalRead(LightLeft)==LOW)
{
goMotors(enLeft,in1,in2,00);
goMotors(enRight,in3,in4,-100);
}
else if(digitalRead(LightRight)==HIGH && digitalRead(LightLeft)==HIGH)
{
//If there is no black line move
goMotors(enLeft,in1,in2,-100);
goMotors(enRight,in3,in4,-100);
}
//Arduino IDE code for Obstacle detecting Robot
const int trig = 12;
const int echo = 11;
long duration, inches, cm;
void setup()
{
Serial.begin(9600);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
pinMode(goMotors enLeft, OUTPUT);
pinMode(goMotors enRIGHT, OUTPUT);
}
void loop()
{
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
//this returns the time duration taken
//for the ultrasonics to hit an obstacle and return
inches = duration / 74 / 2;//converts the time duration into inches
cm = duration / 29 / 2;//converts the time duration to cm
if(cm>15)//checks for the distance is greater than 15cm
//the motor moves forward if the condition is true
digitalWrite(goMotors enLeft,HIGH);//Both the motors are moving
digitalWrite(goMotors enRight,HIGH);
Serial.print(“No obstacle detected”);
}
else
//the robot turns left when an obstacle is detected
digitalWrite(goMotors enRight,HIGH);//the right motor is in ON state
digitalWrite(goMotors enLeft,LOW);//the left motor is in OFF state
Serial.print(“Obstacle detected”);
delay(100);//this delays the process by 100milliseconds
delay(100);//this delays the code by 0.1 seconds and repeats the loop again
}
IN THIS PROJECT IF WE USE L298N CURRENT DEVIDER WHAT WILL BE THE CIRCUIT PLEASE TELL ME….?
Can u send me the code for white line follower plz……
It would be really useful if you could please explain the code too in short…
This project is very interesting. Did you have other projects like where LabView is involved?
How many volts motors did u use?
12V
Can you please make a easy circuit diagram
You haven’t initialized the sensor pin to INPUT in void setup…..
That may be causing the Arduino to not receive any signal in declared pins
Arduino controller is open source controller it is very useful for all projects. The open source controller is used for real time applications.
Can u plz share the circuit diagram???
Can you explain in detail how the information from the IR sensor passes to the wheels after detection of the line
The information from the ir sensors in sent to arduino. The arduino then send signals to L293D according to what the sensors’ information. The L293D then drives the motors accordng to the signals given to it by arduino. For example, if the sensors detect a right turn tgen tge signals will me sent to arduino, then arduino will tell the L293D to slow the right side motor and fast up the left one and hence te robot will turn right.
Where is the code
Tinotenda – suggest you look up syntax of Arduino functions for your function “goMotors”. It needs to be defined and called in the loop().
//Ultasound sensor
int echoPin = 11;
int trigPin =12;
double RANGE();
void goMotors(int, int, int, int);
Which motors are left motors and which are the right ones??
PLease can anyone send me the code line follow robot using 8 array ir and use of pid and pwd in the program for the accuracy please send me the code of 8 array ir so that i can make it in better way please.
My sensors are actually giving the opposite output…I mean on black it is giving output as 1 instead of 0 so what changes should I made in this code for the appropriate turns
hello giovanni,
ir (infra red) sensors work with either black or white stripes. the difference is that white sends the ir light back and black doesnt, that is on your choice to pragrammit the way you want.
hye,can i ask? if i put virtual terminal and logic state?what program can i use?can u you show me pls?
i need it to show whether it move forward or turn left or turn right and stop
Is battery is connected to aurdino or motors?
Sir I am trying to make the same robot but while compiling I am getting error whit should I do please sujjest me
My email nabinsharma74916@gmail.com
How much does it cost to make it
So interesting i like it.