Muhammad Ansar
Published

Line Follower Robot

Line Follower Robot using Arduino UNO, IR sensor and L298 motor driver

BeginnerFull instructions provided6
Line Follower Robot

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
DC Motor, 12 V
DC Motor, 12 V
×1
2-pin MTE Power Cable
Digilent 2-pin MTE Power Cable
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
Maker Essentials - Micro-motors & Grippy Wheels
Pimoroni Maker Essentials - Micro-motors & Grippy Wheels
×1
Resistor 1k ohm
Resistor 1k ohm
×1
5 mm LED: Red
5 mm LED: Red
×1
Rocker Switch, SPST
Rocker Switch, SPST
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Materia 101
Arduino Materia 101

Story

Read more

Custom parts and enclosures

Components

Components Details () {
Arduino UNO,
ROBOT 3 WHEELS VEHICLE CHASSIS,
IR Sensor x 3,
male to female jumper wires,
female DC pin,
4007 Diode,
1k resistor ,
LED,
L298 Motor Driver,
Switch On/Off,
Battery 8.2v
}

Schematics

Schematics and circuit diagrams

Code

code

C/C++
int S_A = 10;  //speed motor a
int M_A1 = 2; //motor a = +
int M_A2 = 3; //motor a = -
int M_B1 = 4; //motor b = -
int M_B2 = 5; //motor b = +
int S_B = 11;  //speed motor b

int R_S = A0; //sincer R
int S_S = A1; //sincer S
int L_S = A2; //sincer L

void setup() 
{
pinMode(M_B1, OUTPUT);
pinMode(M_B2, OUTPUT);
pinMode(M_A1, OUTPUT);
pinMode(M_A2, OUTPUT);
pinMode(S_B, OUTPUT);
pinMode(S_A, OUTPUT);

pinMode(L_S, INPUT);
pinMode(S_S, INPUT);
pinMode(R_S, INPUT);

analogWrite(S_A, 150); 
analogWrite(S_B, 150); 
delay(200);
}
void loop()
{  
if ((digitalRead(L_S) == 0)&&(digitalRead(S_S) == 1)&&(digitalRead(R_S) == 0)){forword();}

if ((digitalRead(L_S) == 1)&&(digitalRead(S_S) == 1)&&(digitalRead(R_S) == 0)){turnLeft();}
if ((digitalRead(L_S) == 1)&&(digitalRead(S_S) ==0)&&(digitalRead(R_S) == 0)) {turnLeft();}

if ((digitalRead(L_S) == 0)&&(digitalRead(S_S) == 1)&&(digitalRead(R_S) == 1)){turnRight();}
if ((digitalRead(L_S) == 0)&&(digitalRead(S_S) == 0)&&(digitalRead(R_S) == 1)){turnRight();}

if ((digitalRead(L_S) == 1)&&(digitalRead(S_S) == 1)&&(digitalRead(R_S) == 1)){Stop();}
}

void forword(){
digitalWrite(M_A1, LOW);
digitalWrite(M_A2, HIGH);
digitalWrite(M_B1, HIGH);
digitalWrite(M_B2, LOW);  
}


void turnRight(){
digitalWrite(M_A1, LOW);
digitalWrite(M_A2, LOW);
digitalWrite(M_B1, HIGH);
digitalWrite(M_B2, LOW);  
}

void turnLeft(){
digitalWrite(M_A1, LOW);
digitalWrite(M_A2, HIGH);
digitalWrite(M_B1, LOW);
digitalWrite(M_B2, LOW);
}

void Stop(){
digitalWrite(M_A1, LOW);
digitalWrite(M_A2, LOW);
digitalWrite(M_B1, LOW);
digitalWrite(M_B2, LOW);
}

Credits

Muhammad Ansar

Muhammad Ansar

3 projects • 17 followers

Comments

Add projectSign up / Login