hello guys

hello guys

int M1 = 6;
int M2 = 9;
int M3 = 10;
int M4 = 11;

int IR_Left = 8;
int IR_Right = 3;

void setup() {
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(M3, OUTPUT);
pinMode(M4, OUTPUT);

pinMode(IR_Right, INPUT);
pinMode(IR_Left, INPUT);
Serial.begin(9600);
}

void loop() {
Serial.print(“Right_IR: “);
Serial.print(digitalRead(IR_Right));
Serial.print(” Left_IR: “);
Serial.print(digitalRead(IR_Left));
Serial.println();

if (digitalRead(IR_Right) == 0 && digitalRead(IR_Left == 1))
{
digitalWrite(M1, HIGH);//Left Motor ON
digitalWrite(M2, LOW);
digitalWrite(M3, LOW);//Right Motor OFF
digitalWrite(M4, LOW);
}
else if (digitalRead(IR_Left) == 0 && digitalRead(IR_Right == 1))
{
digitalWrite(M3, HIGH);//Right Motor ON
digitalWrite(M4, LOW);
digitalWrite(M1, LOW);//Left Motor OFF
digitalWrite(M2, LOW);
}
else
{
digitalWrite(M1, LOW);//Left Motor OFF
digitalWrite(M2, LOW);
digitalWrite(M3, LOW);//Right Motor OFF
digitalWrite(M4, LOW);
}
}

Scroll to Top