I've tried many codes for this to work but anything isn't helping at all, so my code should work like this: If a sound sensor (3 pins, A2) sends 5 signals into the Arduino within 10 seconds (the time gap of every signal varies, but doesn't matter as long as it sends 5 signals), the LED (13) will light up. This is my recent code if it could help
int led=13;
int sensor=A2;
void setup()
{
pinMode(led, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop()
{
unsigned long StartMillis = millis();
unsigned long CurrentMillis = millis();
int signal_count=digitalRead(sensor);
int signal_limit=5;
Serial.println(signal_count);
while ((CurrentMillis - StartMillis)==5000)
if (digitalRead(sensor)=0)
{ signal_count ++;
Serial.println(signal_count);
}
if (signal_count>signal_limit) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led,LOW);
}
}