hi, i am currently doing a project on a robot that will go forward until it senses an obstacle in its path, after this the robot should turn left and keep turning left until it finds an opening but my problem is that the code i have wrote is not working and its a pretty simple and straight forward program can anyone see where i have went wrong in the program.
code -
int motor1f = 12;// motors on rightside go forward
int motor1b = 11; // motors on rightside go backward
int motor2f = 10; // motors on leftside go forward
int motor2b = 9; // motors on leftside go backward
int sensor1 = 8;// IR sensor on left
int sensor2 = 7;//IR sensor on right
int sensorState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(motor1f, OUTPUT);
pinMode(motor1b, OUTPUT);
pinMode(motor2f, OUTPUT);
pinMode(motor2b, OUTPUT);
pinMode(sensor1, INPUT);
pinMode(sensor2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// the robot should drive forward
digitalWrite (motor1f, HIGH);
digitalWrite (motor2f, HIGH);
digitalWrite (motor1b, LOW);
digitalWrite (motor2b, LOW);
sensorState = digitalRead (sensor1&sensor2);
// if the robot detects something in its path it will turn left until it finds an opening
if (sensorState == HIGH){
digitalWrite(motor1f, LOW);
digitalWrite(motor2f, LOW);
delay(500);
digitalWrite(motor1f, HIGH);
digitalWrite(motor2b, HIGH);
}
}
robot_wheels_program.ino (816 Bytes)