Hi all,
In my project I'm using a Sound input module + UNO board + LED
I'm trying to count a certain number of pulses using an op-amp connected to the sound module.
In addition, I'm interested on counting these pulses on certain amount of duration.
The LED will turn on if this certain amount of pulses occurs on this duration.
I uploaded the following code :
const byte LED = 13;
const byte MIC = 2;
int count=0;
int time=0;
// Interrupt Service Routine (ISR)
void pinChange ()
{
if(digitalRead (MIC) == HIGH)
{
count++;
Serial.println(count);
if (count==14)
{
count=0;
digitalWrite (LED, HIGH);
delay(100);
}
}
else
{
digitalWrite (LED, LOW);
delay(100);
}
} // end of pinChange
void setup ()
{
Serial.begin(9600);
pinMode (LED, OUTPUT); // so we can update the LED
digitalWrite (MIC, HIGH); // internal pull-up resistor
attachInterrupt (0, pinChange, CHANGE); // attach interrupt handler
} // end of setup
void loop ()
{
// loop doing nothing
}
This code counted the number of pulses and when reaching a 14 pulse LED turns on for a while and then start counting again.
The problem I'm facing now is how to count the pulses in certain amount of time. For example , count the number of pulses in 10 seconds only. If the number of pulses reaches 14 in these 10 seconds turn the LED on and start time and count again.
I tried some different loops like for, while but nothing works. I also tried to understand the timers but it was complicated specially that I'm still a beginner in Arduinos and my time is limited.
I would be thankful if any one could help me.
Thanks in advance.