user63469: 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);
    }
}


user2967: Your handling of millis() is wrong. With these two lines:
unsigned long StartMillis = millis();
unsigned long CurrentMillis = millis();

StartMillis will always have the same value as CurrentMillis. (Ok, I guess its possible for millis() to return a value that's increased by 1 the second time it's called, but that is extremely unlikely. The 2 lines takes much less than a millisecond to execute.)
Your 
while ((CurrentMillis - StartMillis)==5000) 

will never evaluate to true, so the code in the while block will never execute.
This if statement is also wrong:
if (digitalRead(sensor)=0)

You want == (comparison) not = assignment. I'm surprised the compiler even allowed that to compile, since you are trying to set the function digitalRead(sensor) to 0, which doesn't make sense.
Change that code to read:
if (digitalRead(sensor)==0)

(Assuming you want the body of the if statement to execute when your sensor value is 0.)

63469: <p>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</p>

<pre><code>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&gt;signal_limit) {
        digitalWrite(led, HIGH);
    }
    else {
    digitalWrite(led,LOW);
    }
}
</code></pre>
 2967: <p>Your handling of <code>millis()</code> is wrong. With these two lines:</p>

<pre><code>unsigned long StartMillis = millis();
unsigned long CurrentMillis = millis();
</code></pre>

<p><code>StartMillis</code> will always have the same value as <code>CurrentMillis</code>. (Ok, I guess its possible for <code>millis()</code> to return a value that's increased by 1 the second time it's called, but that is <strong>extremely</strong> unlikely. The 2 lines takes much less than a millisecond to execute.)</p>

<p>Your </p>

<pre><code>while ((CurrentMillis - StartMillis)==5000) 
</code></pre>

<p>will never evaluate to true, so the code in the while block will never execute.</p>

<p>This <code>if</code> statement is also wrong:</p>

<pre><code>if (digitalRead(sensor)=0)
</code></pre>

<p>You want <code>==</code> (comparison) not <code>=</code> assignment. I'm surprised the compiler even allowed that to compile, since you are trying to set the function <code>digitalRead(sensor)</code> to 0, which doesn't make sense.</p>

<p>Change that code to read:</p>

<pre><code>if (digitalRead(sensor)==0)
</code></pre>

<p>(Assuming you want the body of the if statement to execute when your sensor value is 0.)</p>
