#define LS 2 // left sensor #define RS 3 // right sensor
/-------definning Outputs------/
int LM1= 5; // left motor
int LM2= 6; // left motor
int RM1= 9; // right motor
int RM2= 10;
void setup()
{ 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);
#define LS 2 // left sensor
#define RS 3 // right sensor
/*-------definning Outputs------*/
int LM1= 5; // left motor
int LM2= 6; // left motor
int RM1= 9; // right motor
int RM2= 10;
void setup()
{
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);
}
else if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right {
}
else if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right
{
digitalWrite(LM1,HIGH);
digitalWrite(LM2, LOW);
analogWrite(RM1,70);
digitalWrite(RM2,LOW);
}
else if(digitalRead(LS) && !(digitalRead(RS))) // turn left {
}
else if(digitalRead(LS) && !(digitalRead(RS))) // turn left
{
analogWrite(LM1,70);
digitalWrite(LM2, LOW);
digitalWrite(RM1,HIGH);
digitalWrite(RM2,LOW);
}else{
digitalWrite(LM1, LOW);
}else{ digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1,LOW);
digitalWrite(RM2, LOW);
}
}
}
}
/-------definning Inputs------/
#define LS 2 // left sensor
#define RS 3 // right sensor
/-------definning Outputs------/
int LM1= 5; // left motor
int LM2= 6; // left motor
int RM1= 9; // right motor
int RM2= 10; //right motor
int tmp;
void setup()
{
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
{
/*-------definning Inputs------*/
#define LS 2 // left sensor
#define RS 3 // right sensor
/*-------definning Outputs------*/
int LM1= 5; // left motor
int LM2= 6; // left motor
int RM1= 9; // right motor
int RM2= 10; //right motor
int tmp;
void setup()
{
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);
}
else if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right {
}
else if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right
{
digitalWrite(LM1,HIGH);
digitalWrite(LM2, LOW);
analogWrite(RM1,70);
digitalWrite(RM2,LOW);
tmp=1; }
else if(digitalRead(LS) && !(digitalRead(RS))) // turn left {
tmp=1;
}
else if(digitalRead(LS) && !(digitalRead(RS))) // turn left
{
analogWrite(LM1,70);
digitalWrite(LM2, LOW);
digitalWrite(RM1,HIGH);
digitalWrite(RM2,LOW);
tmp=2;
}
else//out of the line
}
else//out of the line{
if(tmp=1){ analogWrite(LM1,70);
{
if(tmp=1){
analogWrite(LM1,70);
digitalWrite(LM2, LOW);
digitalWrite(RM1,LOW);
analogWrite(RM2,70);
}else if(tmp=2){
digitalWrite(LM1,LOW);
}else if(tmp=2){
digitalWrite(LM1,LOW);
analogWrite(LM2, 70);
analogWrite(RM1,70);
digitalWrite(RM2,LOW);
}
}
}
}
}
}