// Include Wire Library for I2C #include // Include NewLiquidCrystal Library for I2C #include // Include EEPROM Library #include // Define LCD pinout const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3; // Define I2C Address - change if reqiuired const int i2c_addr = 0x27; LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE); const int BUTTON_PIN = 7; const int RELAY_PIN = 3; int counter=1; int i; int liter; void setup() { Serial.begin(9600); // initialize serial pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode lcd.begin(16, 2); // Set display type as 16 char, 2 rows lcd.setCursor(0, 0); lcd.print("System is ready"); lcd.setCursor(0, 1); lcd.print("Prev Count:"); counter = EEPROM.read(0); //get the previously saved value from EEPROM address zero lcd.setCursor(14, 1); lcd.print(counter-1); } void loop() { int buttonState = digitalRead(BUTTON_PIN); // read new state if (buttonState == LOW) { digitalWrite(RELAY_PIN, HIGH); // turn on } else if (buttonState == HIGH) { digitalWrite(RELAY_PIN, LOW); // turn off i = counter++; lcd.clear(); lcd.setCursor(0, 0); lcd.print("Pomp Count:"); lcd.setCursor(14, 0); lcd.print(i); lcd.setCursor(0, 1); lcd.print("Volume:"); lcd.setCursor(9, 1); liter = (i * 25); lcd.print(liter); lcd.print(" L"); lcd.setCursor(15, 1); {EEPROM.update(0, counter); //save the new value to EEPROM address zero delay(10000); //10 seconds } } }