One Sensor Line follower Arduino code
void setup()
{
pinMode(4,OUTPUT); //enable a
pinMode(8,OUTPUT); //enable b
pinMode(2,OUTPUT); //motor A
pinMode(3,OUTPUT);//motor A
pinMode(10,OUTPUT);//motor b
pinMode(9,OUTPUT);//MOTOR B
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(4,HIGH);
digitalWrite(8,HIGH);
int lsen,rsen;
lsen=digitalRead(5);
rsen=digitalRead(6);
Serial.println(lsen);
if((lsen==HIGH)&&(rsen==LOW))
{
right();
}
else if((rsen==HIGH)&&(lsen==LOW))
{
left();
}
else if((rsen==HIGH)&&(lsen==HIGH))
{
Stop();
}
}
void right()
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
}
void left()
{
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
}
void Stop()
{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
{
pinMode(4,OUTPUT); //enable a
pinMode(8,OUTPUT); //enable b
pinMode(2,OUTPUT); //motor A
pinMode(3,OUTPUT);//motor A
pinMode(10,OUTPUT);//motor b
pinMode(9,OUTPUT);//MOTOR B
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(4,HIGH);
digitalWrite(8,HIGH);
int lsen,rsen;
lsen=digitalRead(5);
rsen=digitalRead(6);
Serial.println(lsen);
if((lsen==HIGH)&&(rsen==LOW))
{
right();
}
else if((rsen==HIGH)&&(lsen==LOW))
{
left();
}
else if((rsen==HIGH)&&(lsen==HIGH))
{
Stop();
}
}
void right()
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
}
void left()
{
digitalWrite(10,HIGH);
digitalWrite(9,LOW);
}
void Stop()
{
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
}
DOWNLOAD THE ARDUINO CODE
No comments:
Post a Comment