volatile int flow_frequency; // Measures flow sensor pulses unsigned char flowsensor = 2; // Sensor Input unsigned long currentTime; unsigned long cloopTime; int pinOut = 10; void flow () // Interrupt function { flow_frequency++; } void setup() { pinMode(flowsensor, INPUT); pinMode(pinOut, OUTPUT); digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up attachInterrupt(0, flow, RISING); // Setup Interrupt sei(); // Enable interrupts currentTime = millis(); cloopTime = currentTime; } void loop () { currentTime = millis(); // Every second, calculate and print litres/hour if(currentTime >= (cloopTime + 1000)) { cloopTime = currentTime; // Updates cloopTime // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. if(flow_frequency > 0) { digitalWrite(pinOut, LOW); } else { digitalWrite(pinOut, HIGH); } flow_frequency = 0; // Reset Counter } }