#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int flowSensorPin = A0; // analog pin for the flow sensor
float flowRate; // flow rate in liters per minute
float totalFlow; // total flow in liters
unsigned long timeElapsed; // time elapsed since last flow calculation
unsigned long oldTime; // old time in milliseconds
void setup() {
lcd.begin(16, 2);
timeElapsed = 0;
oldTime = millis();
}
void loop() {
int rawFlow = analogRead(flowSensorPin); // read the analog input from the flow sensor
flowRate = (rawFlow / 1024.0) * 5.0 / 2.25; // convert the raw flow reading to liters per minute
totalFlow += flowRate * timeElapsed / 60000.0; // calculate the total flow based on the flow rate and time elapsed
timeElapsed = millis() - oldTime; // calculate the time elapsed since last flow calculation
oldTime = millis(); // store the current time for the next flow calculation
lcd.setCursor(0, 0);
lcd.print("Flow rate: ");
lcd.print(flowRate, 2); // display the flow rate value on the LCD display with two decimal places
lcd.print(" L/min");
lcd.setCursor(0, 1);
lcd.print("Total flow: ");
lcd.print(totalFlow, 2); // display the total flow value on the LCD display with two decimal places
lcd.print(" L");
delay(500);
}