Assalam o alikum!
this article will show code and circuit diagram of l.f.r
this article will show code and circuit diagram of l.f.r
1) this diagram show's how l.f.r work's
2) when lfr is on track (following black line).
moving forward,left,right and stoping.
circuit diagram
---------x-------x-----x------x------x-------x------x------x------x------x-----x-----x------x-----x----x----------
CODE
/*------ Arduino Line Follower Code----- */
/*-------definning Inputs------*/
#define LS 2 // left sensor
#define RS 3 // right sensor
/*-------definning Inputs------*/
#define LS 2 // left sensor
#define RS 3 // right sensor
/*-------definning Outputs------*/
#define LM1 4 // left motor
#define LM2 5 // left motor
#define RM1 6 // right motor
#define RM2 7 // right motor
#define LM1 4 // left motor
#define LM2 5 // left motor
#define RM1 6 // right motor
#define RM2 7 // right motor
void setup()
{
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}
{
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}
void loop()
{
if(digitalRead(LS) && digitalRead(RS)) // Move Forward
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
if(digitalRead(LS) && !(digitalRead(RS))) // turn left
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
if(!(digitalRead(LS)) && !(digitalRead(RS))) // stop
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
{
if(digitalRead(LS) && digitalRead(RS)) // Move Forward
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
if(digitalRead(LS) && !(digitalRead(RS))) // turn left
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
if(!(digitalRead(LS)) && !(digitalRead(RS))) // stop
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
}
No comments:
Post a Comment