I have a sound sensor that was working perfectly fine as I was using it as a clap sensor to turn lights on and off. However, I tried to change the code to make it work a little smoother and for whatever reason it stopped working. I then tried to write a very simple script to allow it to turn on and off using just one clap but now it treats the sound sensor as if it's always inputting HIGH. Any ideas why this might be happening?
note: I've turned up the sensitivity and can see that the sound sensor isn't always HIGH. Even when it's too high to hear me clap it still turns the LED on and off as if the if statement below was always true.
int SENSOR = 2;
int LED = 13;
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);
pinMode(SENSOR, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(SENSOR) == HIGH){
digitalWrite(LED, (digitalRead(LED) == HIGH ? LOW : HIGH));
delay(100);
}
}
This is the sound sensor module I am using: Robojax Sound Detection Microphone Module