Line Follower
Line Follower
Line Follower
ino Arduino
// Black Line Follower
int IR1=8; //Right sensor
int IR2=9; //left Sensor
// motor one
int enA = 5; //Right motor
int MotorAip1=2;
int MotorAip2=3;
// motor two
int enB = 6; //Left motor
int MotorBip1=4;
int MotorBip2=7;
void setup()
{
// put your setup code here, to run once:
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(IR1,INPUT);
pinMode(IR2,INPUT);
pinMode(MotorAip1,OUTPUT);
pinMode(MotorAip2,OUTPUT);
pinMode(MotorBip1,OUTPUT);
pinMode(MotorBip2,OUTPUT);
}
void loop()
{
if(digitalRead(IR1)==HIGH && digitalRead(IR2)==HIGH) //IR will not
glow on black line
{
//Stop both Motors
digitalWrite(MotorAip1,LOW);
digitalWrite(MotorAip2,LOW);
digitalWrite(MotorBip1,LOW);
digitalWrite(MotorBip2,LOW);
analogWrite (enA, 0);
analogWrite (enB, 0);
}
else
{
//Stop both the motors
digitalWrite(MotorAip1,LOW);
digitalWrite(MotorAip2,LOW);
digitalWrite(MotorBip1,LOW);
digitalWrite(MotorBip2,LOW);
analogWrite (enA, 0);
analogWrite (enB, 0);
}
}