arduino + motor

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);
}

part names? How is all this connected?
It worked… then didn’t ? smell smoke?

Are you driving the motor using an 'h-bridge'?

I can see you are setting the direction by changing the polarity of two pins. I hope you haven't directly connected it to arduino pins, these can't supply much current.

For your light sensor, this will only update once every 10 or 11 seconds, you will need to learn about doing multiple things at the same time to improve this