int soungTrig = A0; // input for the sound trigger int lightPin = 5;// output of the light int buzzer = 9; // output for buzzer int soundstate = 0; // reading the value for of the sound trigger // Timer unsigned long previousMillis = 0; long interval = 5000; void setup() { Serial.begin(9600); pinMode(soungTrig, INPUT); // input sound trigger pinMode(lightPin, OUTPUT); // output light pinMode(buzzer, OUTPUT); // output buzzer } void loop() { unsigned long currentMillis = millis(); soundstate = digitalRead(soungTrig); // if sound trigger is off and timer is greater than our interval, sound the alarm if(currentMillis - previousMillis > interval && soundstate == LOW) { digitalWrite(buzzer, HIGH); } else { digitalWrite(buzzer, LOW); } if (soundstate == HIGH){ previousMillis = currentMillis; // reset timer digitalWrite(lightPin, HIGH); // outputs lights }else{ digitalWrite(lightPin, LOW); // does not output light } }