read a sensor for 10" and only after write data

hi, I'm working on a project with a sound sensor that should be placed in a library... The idea is measure the noisy's level and to turn on a led in case the level is higher than accepted. At that moment the led is turning on when the level detected is high but I need to find a way to make the sensor reading data for a predeterminated time before turn on the led. (so I can be sure that the alert works only in case of effective noise and not if someone is coughing).

any suggestion?

thanks in advance

Loop around until the level is exceeded then read the sensor in a loop for the required time. If the noise level drops for more than a set time, exit and reset timer. You must not use delay() as this will stop all other processing.

Weedpharma

ok, can I ask you tu write down a sketch for example? mine is the following:

#include <Makeblock.h>
#include <Bridge.h>
#include <BlynkSimpleYun.h>
#include <SimpleTimer.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define BLYNK_PRINT Serial

char auth[] = "27a337d5df5d408dacf01f063f3a2dd2";

 SimpleTimer timer;
int noise = 0;
const int soglia = 400;
int sound;
const int numReadings = 10;
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
WidgetLCD lcd(3);

MeSoundSensor mySound(A0);
void setup()
{
    Serial.begin(9600);
    Blynk.begin(auth);
    pinMode(13, OUTPUT);
    Blynk.virtualWrite(noise,LOW);
    // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
    lcd.clear(); 
  }
}

void sendUptime()
{
  sound = mySound.strength(); //legge il segnale audio
  Blynk.virtualWrite(5, sound);
}


void loop(){
  lcd.clear();
  Blynk.run(); // and the magic begin
   timer.run(); // Initiates SimpleTimer
   Blynk.virtualWrite(5, average);
   total = 0;
  for(readIndex = 0; readIndex < numReadings; readIndex++){
    // read from the sensor:
  readings[readIndex] = mySound.strength();
  // add the reading to the total:
  total += readings[readIndex];
  
  delay(50);
  }
  // calculate the average:
  average = total / numReadings;
lcd.print(4,0,average);
   if(average>soglia){
    Blynk.virtualWrite(noise, HIGH);
    digitalWrite(13,HIGH);
   }
    else {
    Blynk.virtualWrite(noise, LOW);
     digitalWrite(13,LOW);
   }
 
}

Take a look at the Blink Without Delay example in the Arduino IDE. That will show you have to do something after a certain period of time.