Millis() Function with Relay Connected to Motor

I connected my motor to a relay module and everything is working fine, but the timer that I created is what is causing trouble. What I wish to achieve is for my motor to activate after 5 seconds of the light being on and stay on until the photoresistor no longer detects light. It is able to achieve that, but after a few trials, the relay activates as soon as the photoresistor detects light. I can temporarily fix this by pressing the reset button, but again after a few trials, it is the same again.
I have provided a video:

int analogValue;
int voltage;
int timer = millis();
void setup()
  pinMode(A0, INPUT);
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);

void loop()
  analogValue = analogRead(A0);
  analogWrite(7, voltage);
  if(analogValue > 200){
    if((millis() - timer) >10000){
    digitalWrite(7, HIGH);
        timer = millis();
       digitalWrite(7, LOW);

I see the mistake. Use unsigned long timer = millis();

That seems to have fixed it! Thank you very much.

No problem. Nice to contribute.
I also make hasty mistakes.
Look at this:

variableA += 10;//increments variableA by 10
boolVariableA = !boolVariableA;
is not the same as:
boolVariableA != boolVariableA;//!!!!!!! != means "not equal to"...