/*
Flow Sensor Counter Meter FS300A G3/4
Flow rate : 1-60L/min
Flow Pulse: 508 pulse / Liter
*/
#define FS300A_PULSE 508 // PULSE / LITER
#define FS300A_FLOW_RATE 60 // LITER / MINUTE
const float factor = 60.0F / 508.0F; // FS300A_FLOW_RATE / FS300A_PULSE
#define interruptPin 2
uint16_t pulse;
uint16_t count;
float frequency;
float flowRate;
bool busy;
void setup() {
Serial.begin(115200);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), FlowInterrupt, CHANGE);
}
void loop() {
Frequency();
}
void FlowInterrupt() {
busy = true;
pulse++;
busy = false;
}
void Frequency() {
static unsigned long startTime;
if (micros() - startTime < 1000000UL ) return; // 1000 milliseconds Interval
startTime = micros();
while (busy) {};
uint8_t sreg = SREG;
cli();
count = pulse;
pulse = 0;
SREG = sreg;
frequency = count / 2.0f;
flowRate = frequency * factor;
PlotInfo();
}
void PlotInfo() {
Serial.print("Freq.:= " + String(frequency, 2) + " Hz");
Serial.println(", FLow:= " + String(flowRate, 3) + " L/min");
}