Making Arduino count time under the stimuli

Hi everyone, I am hoping to make my arduino count time under stimuli and I need your help.
I want to make my arduino turn on the light by servo-motor when my phone alarm rings.
But since it should not turn it on any random sounds, I want to make it move after 10 seconds of consecutive noise.

#include <Servo.h>
Servo myServo;
int threshold=1000;
int sound;
int i=0;

void setup(){
  myServo.attach(11);
  myServo.write(0);
  Serial.begin(9600);

}

void loop(){
  sound=analogRead(A0);
  int ValA0=analogRead(A0);
  Serial.println(ValA0);
  if(sound >= threshold){
    i++;
    if(i=20){
      myServo.write(180);
      i=0;
    }
  }
}

this is my code, but it seems it doesn't work.
I try to add 1 in integer 'i' whenever sounds larger than certain threshold come and
if i becomes 20, I tried to make the servomotor move.
I know even if it does work it contains problems like it cannot count sounds in serial, but
in this stage, I don't even know why this basic function doesn't even work.

Can you give me a help?

You're making it count up to 20. That is going to take it a couple of milliseconds to get to 20. You need to look at the millis function. It records the time since the board last reset. You could use that to see how long it has been since you first heard noise.