I have a water meter that I am reading. It has a simple pulse output that I am reading with PIN 3 on my Leonard. I am doing this with a interrupt and I am having some basic issues.. I want to repurpose this meter to maybe catch a leak in my Hydroponics system. So what I need to do is see if it is pulsing AKA water flowing, then time how log it flows. When the system shuts down after running for 5 min there should be no flow until it starts back up. If there is flow (pluses) then a leak is the issue. So my system runs for 5 min an hour and if it runs more than that I am leaking. I can read flow from the meter and I can guess how much but I don't want to I just want to see if it flows or not. Now because of the interrupt I cant time how long it flows for. So does anyone know a method I can use that I can read the pulse output meter and also time for how long it has been running continuously? one more thing, in low flow situations it pulses about once every 24 sec, so lets say I set it to alert me when water flows for 15min if it is flowing slow it only pulses once every 24sec so it has to maybe only read 30sec at a time and if no pulse for 30 sec then stop timer but if a pulse keep timing. Here is as far as I have gotten code wise. It only lights the LED when the meter moves at all. And my else statement is not turning the LED off even after the flow stops.
//interrupt that the pin is connected to, the flow meter
int flowMeterInt = 0; // PIN 3
long flowTime = 0;
void setup() {
// put your setup code here, to run once:
//I think you do this to set rate in serial
Serial.begin(115200);
//Interrupt code.. im using leanardo so int.0 is on PIN 3
attachInterrupt(flowMeterInt, leakFlow, FALLING);
}
void leakFlow()
{
//this tells if the water is flowing and lights a LED
if(flowMeterInt, FALLING)
{
digitalWrite(13,HIGH);
}
//This shuts off the LED when it stops.
else
{
digitalWrite(13, LOW);
}
flowTime++;
//This should print a value.
Serial.print(flowTime);
}
void loop()
{
}