Line follower robot with 5 sensor array Arduino

A robot which follows the line is known as a line follower robot. in this tutorial, we are going to make a Line follower robot with 5 sensor array Arduino robot. as we all the simple rule of line follower robot. it follows the black line with the help of some sensor attached to the robot. this sensor help to find the path to the robot. it is a simple robot which uses the pushbutton interfacing concept. in this, we use IR sensor instead of pushbutton but the concept is the same for line follower robot also.

Working of line follower:-

it’s having some IR sensor which helps to detect the black and white color. IR sensor having an IR transmitter and receiver together. In the IR sensor transmitter transmit the infrared Rays, and the receiver receives these Rays. when the Sensor is on the white surface it reflects back the infrared rays and these cause giving us high or 5v voltage in the output. and when the sensor is on dark color especially on black it absorbs the light and sensor will use a 0 logic it means low or 0v  at the output.

on this principle our line follower robot works. when the sensor on the black line it gives some value to the Arduino or any other microcontroller which we are using in the line follower robot. then we take a condition according to the output of the sensor. for example:- if the middle sensor is on the black line and another sensor on the white then the robot will move forward. and there may be many conditions in the program to make your line follower robot. so let’s start with the circuit diagram and code for the robot.

you can make this line follower with 2 sensors, 3 sensors and 5 sensors also it’s your choice. If you want to make with 2 sensor line follower robot with Arduino go through this. but in this tutorial, we are making it with the 5 sensor module of IR. let’s understand the circuit diagram

Line follower robot circuit diagram:-

line follower robot circuit diagram

as you can see the connection easily. if you have any problem in the connection. ask us in comment box.

Line follower robot C code for arduino 

void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);

pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);

}

void loop() {

int L= digitalRead(2); //sensor 1
int AL= digitalRead(3); //sensor 2
int M= digitalRead(4); //sensor 3
int AR= digitalRead(5); //sensor 4
int R= digitalRead(6); //sensor 5

if (L==HIGH && AL==HIGH && M==LOW && AR==HIGH && R==HIGH)

{
digitalWrite(7, HIGH); //motor 2
digitalWrite(8, LOW); //FORWARD
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}

else if(L==HIGH && AL==HIGH && M==HIGH && AR==LOW && R==HIGH)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, HIGH); //RIGHT
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}

else if(L==HIGH && AL==HIGH && M==LOW && AR==LOW && R==HIGH)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, HIGH); //RIGHT
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}

else if(L==HIGH && AL==HIGH && M==HIGH && AR==LOW && R==LOW)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, HIGH); //RIGHT
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}

else if(L==HIGH && AL==LOW && M==HIGH && AR==HIGH && R==HIGH)

{

digitalWrite(7, HIGH); //motor 2
digitalWrite(8, LOW); //LEFT
digitalWrite(9, LOW); //motor 2
digitalWrite(10, HIGH);
}

else if(L==HIGH && AL==LOW && M==LOW && AR==HIGH && R==HIGH)

{

digitalWrite(7, HIGH); //motor 2
digitalWrite(8, LOW); //LEFT
digitalWrite(9, LOW); //motor 2
digitalWrite(10, HIGH);
}

else if(L==LOW && AL==LOW && M==HIGH && AR==HIGH && R==HIGH)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, HIGH); //RIGHT
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}

else if(L==LOW && AL==LOW && M==HIGH && AR==LOW && R==LOW)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, LOW); //RIGHT
digitalWrite(9, LOW); //motor 2
digitalWrite(10, LOW);
}

else if(L==HIGH && AL==HIGH && M==HIGH && AR==HIGH && R==HIGH)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, HIGH); //RIGHT
digitalWrite(9, HIGH); //motor 2
digitalWrite(10, LOW);
}
else if(L==LOW && AL==LOW && M==LOW && AR==LOW && R==LOW)

{

digitalWrite(7, LOW); //motor 2
digitalWrite(8, LOW); //RIGHT
digitalWrite(9, LOW); //motor 2
digitalWrite(10, LOW);
}
else
{
digitalWrite(7, HIGH); //motor 1
digitalWrite(8, LOW); //STOP
digitalWrite(9, HIGH ); //motor 2
digitalWrite(10, LOW);
}

}

upload the sketch in the Arduino. if you want to learn arduino and you are new on the arduino. you learn from our arduino tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *