// Flow sensor
volatile int flow_frequency;
unsigned int l_hour , f_value ;
unsigned long ctTime , flow_val , clooptime ;
void flow () //wter flow ISR
{
flow_frequency++; f_val++;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Flow measurement");
attachInterrupt( 1, flow , RISING); sei() ;
ctTime = millis() ; cloopTime = ctTime ; // water flow
}
void loop() {
ctTime = millis();
if (ctTime >= (cloopTime + 1000))
{
cloopTime = ctTime;
l_hour = (flow_frequency + 60 / 7.5 );
flow_frequency = 0;
Serial.print(" Water sensor : ");
Serial.print(l_hour,DEC);
Serial.print("L/Hr");
}
if (f_val >= 450 )
{
flow_val ++;
f_val = 0 ;
}
Serial.print("\t");
Serial.print(flow_val);
Serial.print("L");
//delay(10); // this speeds up the simulation
}