Line Follower Bot (Using IR Sensor Array)
by Technical_Agent in Circuits > Robots
5640 Views, 1 Favorites, 0 Comments
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.
Supplies
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
Tapes
1 Arduino
Ground
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.
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.
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);
analogWrite(lme,60);
digitalWrite(rmb,LOW);
digitalWrite(rmf,HIGH);
digitalWrite(lmb,LOW);
digitalWrite(lmf,HIGH);
Serial.println("forward"); }
else //move backward
{ analogWrite(rme,50);
analogWrite(lme,50);
digitalWrite(rmb,HIGH);
digitalWrite(rmf,LOW);
digitalWrite(lmb,HIGH);
digitalWrite(lmf,LOW);
Serial.println("backward"); } }
void Turn(bool y) //to turn
{ analogWrite(rme,50);
analogWrite(lme,50);
if (y==true) //move right
{ digitalWrite(rmb,LOW);
digitalWrite(rmf,LOW);
digitalWrite(lmb,LOW);
digitalWrite(lmf,HIGH);
Serial.println("right"); }
else //move left
{ digitalWrite(rmb,LOW);
digitalWrite(rmf,HIGH);
digitalWrite(lmb,LOW);
digitalWrite(lmf,LOW);
Serial.println("left"); } }
void stop()
{ analogWrite(rme,0);
analogWrite(lme,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:
val0=digitalRead(ir0);
val1=digitalRead(ir1);
val2=digitalRead(ir2);
val3=digitalRead(ir3);
val4=digitalRead(ir4);
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); }
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!!