Testing out a flow sensor (http://www.seeedstudio.com/depot/datasheet/water%20flow%20sensor%20datasheet.pdf)
This blinks the LED normal (2 times, at 1 second each) as the loop shows, but when I blow through the flow sensor, it shows the increasing pulses on the serial monitor, but when it reaches the limit, it flashes the LED 3 times, but so fast I can hardly tell. If I change the line to blink(ledPin, 3, 30000);
then it flashes at about one per second!
What is wrong here!?
const int ledPin = 13; //LED pin
volatile int FlowSensorCount; //the counter for the flow sensor
void setup() {
//Setup Pins
pinMode(ledPin, OUTPUT);
attachInterrupt(0, CountPulse, RISING); //turn on interrupt for flow sensor on pin 2
Serial.begin(9600);
}
void loop()
{
Serial.println(FlowSensorCount);
noInterrupts();
if (FlowSensorCount > 30)
{
blink(ledPin, 3, 3000);
delay(5000);
FlowSensorCount = 0;
}
interrupts();
blink ( ledPin, 2, 1000);
delay(2000);
}
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}
void CountPulse()
{
FlowSensorCount++; //increases the count from the interupt pin 2
}