//Sensor input //motor control pins void setup() { // Set the sensor pins to input. // Set the motor pins to output. } void loop() { //corrects for the robot veering to the right if(digitalRead(S1) && digitalRead(S2) && digitalRead(S3)) { analogWrite(E1, 111); analogWrite(E2, 90); digitalWrite(M1, HIGH); digitalWrite(M2, HIGH); } //corrects for the robot veering to the left else if (digitalRead(S4) && digitalRead(S5) && digitalRead(S6)) { analogWrite(E1, 90); analogWrite(E2, 111); digitalWrite(M1, HIGH); digitalWrite(M2, HIGH); } // If the line is in the middle go straight else if (digitalRead(S3) && digitalRead(S4) && (digitalRead(S2) || digitalRead(S5))) { analogWrite(E1, 90); analogWrite(E2, 90); digitalWrite(M1, HIGH); digitalWrite(M2, HIGH); } // Otherwise if it isn't one of these things or the //robot has reached the end of the line, then stop. else { analogWrite(E1, 0); analogWrite(E2, 0); digitalWrite(M1, HIGH); digitalWrite(M2, HIGH); } }