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.