I have written the following code for lighting an LED on a clap ( using sound sensor) that I have connected via a resistance of 330 OHM on pin number 4.
However, when I clap once, close to the sound sensor, it does not lights the LED. But it only lights the LED if I provide prolong exposure to sound ( more than 6 seconds) on the sound sensor.
How can I improve this , so that even if I clap once for a seconds duration, the LED glows?
int soundSensor=10;
int LED=4;
void setup()
{
Serial.begin(9600);
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);
}
void loop()
{
int SensorData=digitalRead(soundSensor);
if(SensorData==1)
{
digitalWrite(LED,HIGH);
delay(3000);
Serial.println("LOUD, LOUD");
delay(1000);
}
else
{
digitalWrite(LED,LOW);
Serial.println("SLOW, SLOW");
delay(1000);
}
}