I have a problem with my engine I want that my car drives 5 seconds forward and 5 seconds backward the first time it happened but the next times it failed. I also want the lights in my car to light up when it is dark, that happens. But can anyone help me with the engine please, thank you.
Here is my code.
const int sensorpin = A0;
const int ledpin1 = 2;
const int sensorconstantvalue = 600 ;
int sensorvalue;
const int ledpin2 = 4;
const int motorpin1 = 3;
const int motorpin2 = 6;void setup() {
pinMode(sensorpin, INPUT);
Serial.begin(9600);
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(motorpin2, OUTPUT);
pinMode(motorpin1, OUTPUT);
delay(5000);}
void loop() {
sensorvalue = analogRead(A0);
Serial.println(sensorvalue);
if (sensorvalue < sensorconstantvalue ) {
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, HIGH);
delay(1000);}
else {
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, LOW);}
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin1, LOW);
delay(10);digitalWrite(motorpin2, HIGH);
digitalWrite(motorpin1, LOW);delay(5000);
digitalWrite(motorpin2, LOW);
digitalWrite(motorpin1, LOW);
delay(10);digitalWrite(motorpin2, LOW);
digitalWrite(motorpin1, HIGH);delay(5000);
}