Code Advice Needed

Hi All,
I am trying to build a sound sensor relay using Adruino Uno. The use case is that a sound sensor will trigger a relay to shutoff and I would like the relay to stay off until a reset switch is pressed.

I was able to get it coded to have a port activate when sound is heard, I tested using an LED. I am unable to figure out the rest, the reset switch to turn off and keep port triggered for relay. Any help would be great.

This is what I have so far.

int led = 13;
int threshold = 200; //Change This
int volume;

void setup() {
Serial.begin(9600); // For debugging
pinMode(led, OUTPUT);
}

void loop() {

volume = analogRead(A0); // Reads the value from the Analog PIN A0
/*
//Debug mode
Serial.println(volume);
delay(100);
*/

if(volume>=threshold){
digitalWrite(led, HIGH); //Turn ON Led
}
else{
digitalWrite(led, LOW); // Turn OFF Led
}

}

You could maintain a status variable say called relayOn instead of directly issuing a digitalWrite() based on the output of the sound sensor.
The relay is on initially, so you set relayOn to true. If the sound sensor > threshold, you set relayOn to false. If the button is pressed you set relayOn to true. Your digitalWrite() statement is conditioned by the value of relayOn.

This is a good loop for any Arduino program, no matter how large...

void loop() {
  checkInputs();
  doCalculations();
  setOutputs();
}

It really does make it easier to program if you seperate the internal logic from the digitalWrite()'s.

If you remove the 'else', the LED will only be turned on based on sound level and not turned off if the sound level goes below 200.

To switch it off, simply read a switch and if it's pressed, turn the LED off; again, no 'else'.