Hi, I have water being supplied to a float-valve. I want to measure the GPM and have added a flow meter with F=(38*Q) the float-valve so I can calculate the GPM.
But I need to know when the float-valve has opened and when it shuts off. Here's where I am at the moment, but cannot seem to get it to do what I need. I am old and the brain is just fuzzing over with this one.
volatile int flowTotal = 0;
int flowLast = 0;
int flowsensor = 2;
bool isRunning = false;
// INTERRUPT ROUTINE
void flow () {
flowTotal++;
}
void calcGPM() {
// I can do this stuff
}
void setup() {
pinMode(flowsensor,INPUT);
digitalWrite(flowsensor,HIGH); // Optional Internal Pull-Up
Serial.begin(115200);
attachInterrupt(0,flowsensor,RISING); // Setup Interrupt
sei(); // Enable interrupts
}
void loop() {
// here is where I am stuck
if (flowTotal == flowLast) {
isRunning = false;
calcGPM();
flowLast = 0;
flowTotal = 0;
} else {
isRunning = true;
flowLast = flowTotal;
}
if (isRunning) {
Serial.print(flowTotal);
Serial.print(", ");
Serial.println("On");
}
}