Introduction: Line Follower Bot (Using IR Sensor Array)

Here's a detailed instruction of making a Line Follower Bot using IR Sensor array. Line follower is a bot which follows black line which is made on a white surface. It can move along with the line and even rotates back in case of a dead end.


1 Bot chassis

1 caster wheel

2 DC motors

2 Wheel

1 Arduino

2 Batteries (12v and 9v)

1 L298n Motor driver

1 IR Sensor Array of 5

Jumper wires


1 Arduino


Step 1: Draw a Rough Diagram

First of all, draw a rough diagram that will represent the end product. As it will help you to get organised and well informed about your bot. Here I have used tinkercad to make my rough project. It makes everything more easy and helps to place everything at right place.

Step 2: Make the Connections

Make the connections according to the following points:

1. Connect both motors with L298n Motor driver. It provides constant power to wheels according to arduino signals provided to it. Then take out 12v and 2 gnd wires from it's front. They will be used to give it power for it's use, for motor and to make ground with arduino.

2. Connect motor wires from Motor driver to arduino.

3. Connect vcc and gnd of IR array to arduino for it's power and IR connections.

All these connections are written in the code so, you can check it from there.

Step 3: Code

const int rme=10,lme=11; //enable pins

const int rmb=8, rmf=9, lmb=12, lmf=13; //motor signals

const int ir0=2, ir1=3, ir2=4, ir3=5, ir4=6; //ir signals white=1 and black=0

int val0=0, val1=0, val2=0, val3=0, val4=0; //variables void

InALine(bool x) //to move in a line

{ if(x==true)

{ analogWrite(rme,60);






Serial.println("forward"); }

else //move backward

{ analogWrite(rme,50);






Serial.println("backward"); } }

void Turn(bool y) //to turn

{ analogWrite(rme,50);


if (y==true) //move right

{ digitalWrite(rmb,LOW);




Serial.println("right"); }

else //move left

{ digitalWrite(rmb,LOW);




Serial.println("left"); } }

void stop()

{ analogWrite(rme,0);


Serial.println("stop"); }

void setup()

{ // put your setup code here, to run once:

pinMode(rmb, OUTPUT);

pinMode(rmf, OUTPUT);

pinMode(lmb, OUTPUT);

pinMode(lmf, OUTPUT);

pinMode(rme, OUTPUT);

pinMode(lme, OUTPUT);

pinMode(ir0, INPUT);

pinMode(ir1, INPUT);

pinMode(ir2, INPUT);

pinMode(ir3, INPUT);

pinMode(ir4, INPUT);

Serial.begin(9600); }

void loop()

{ // put your main code here, to run repeatedly:






if(val0 && val1 && !val2 && val3 && val4) //forward

{ bool x=true; InALine(x); }

else if(val0 && val1 && val2 && !val3 && !val4) //turn right

{ bool y=true; Turn(y); }

else if(!val0 && !val1 && val2 && val3 && val4) //turn left

{ bool y=false; Turn(y); }

else if(!val0 && !val1 && !val2 && !val3 && !val4) //stop

{ stop(); }

else if(val0 && val1 && val2 && val3 && val4) //circle

{ bool y=false; Turn(y); }

else if(!val0 && !val1 && val2 && !val3 && !val4) //in a t-shape condition turn left

{ bool y=false; Turn(y); }

else if(val0 && val1 && !val2 && !val3 && !val4) //in a forward and left condition turn left

{ bool y=false; Turn(y); }

else if(!val0 && !val1 && !val2 && val3 && val4) //in a forward and right condition go straight

{ bool x=true; InALine(x); }

else { bool x=false; InALine(x); }

delay(1000); }

Step 4: Upload the Code and Have a Dry Run

To make the track use the black tape over white surface. The bot will follow the black tape.

Now upload the code and place bot on the track.
You may have to change the value of delay to your accordance and value of enable signals for speed.

After all the settings you are good to go!!

Robotics Contest

Participated in the
Robotics Contest