Arduino library for Flow Sensor.
The SensorConstant is different for different models.
Q = Flowrate (Liter/minute)
#include <WaterFlow.h>
//SensorConstant is 65
WaterFlow waterFlow(PIN2, 65);
param userFunc
void count() {
waterFlow.pulseCount();
}
//The begin function must be called from the setup function
void setup() {
waterFlow.begin(count);
}
//The read function must be called from the loop function
void loop() {
waterFlow.read();
}
return Flowrate
(L/m)
float getFlowRateOfMinute()
return Flowrate
(mL/s)
int getFlowRateOfSecond()
return Volume
(mL)
long getVolume()
void clearVolume()
return true or false
bool isFlowing()
void setListeners(void (*start)(void), void (*stop)(void));
#include "WaterFlow.h"
WaterFlow waterFlow(PIN2, 65);
unsigned long beforeTime;
void count() {
waterFlow.pulseCount();
}
//Make a sound when starting or stopping.
void buzz(){
tone(3, 800, 500);
}
void setup() {
waterFlow.begin(count);
waterFlow.setListeners(buzz, buzz);
Serial.begin(9600);
}
void loop() {
waterFlow.read();
if ((millis() - beforeTime) >= 1000){
beforeTime = millis();
if(!waterFlow.isFlowing()){
waterFlow.clearVolume();
return;
}
Serial.print(waterFlow.getFlowRateOfMinute());
Serial.print(" L/m ");
Serial.print(waterFlow.getFlowRateOfSecond());
Serial.print(" mL/s ");
Serial.print(waterFlow.getVolume());
Serial.println(" mL");
}
}