/** * @file Read_Flow_Rate.ino * @author Hafidh Hidayat (hafidhhidayat@hotmail.com) * @brief * * @copyright Copyright (c) 2022 * * Github : * https://github.com/hafidhh * https://github.com/hafidhh/FlowSensor-Arduino */ #include #include #define pin D2 // pin -> interrupt pin FlowSensor Sensor(7055, pin); //pulses for 1 liter given by the manufacturer, pin = D2 unsigned long timebefore = 0; // Same type as millis() // Uncomment if use ESP8266 and ESP32 // void IRAM_ATTR count() // { // Sensor.count(); // } // Comment if use ESP8266 and ESP32 void count() { Sensor.count(); } void setup() { Serial.begin(115200); Sensor.begin(count); } void loop() { if (millis() - timebefore >= 1000) { Sensor.read(); Serial.print("Flow rate (L/minute) : "); Serial.println(Sensor.getFlowRate_m()); timebefore = millis(); } }