#include <LiquidCrystal.h>
const int Button1Pin = 8; // Digital pin for button 1
const int Button2Pin = 9; // Digital pin for button 2
const int Button3Pin = 10; // Digital pin for button 3
const int WaterPumpPin = 7; // Digital pin for the water pump
int RS, En, D0, D1, D2, D3;
const int rs = 12, en = 11, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long startTime = 0;
unsigned long pumpDuration = 0;
bool pumpRunning = false;
void setup() {
pinMode(Button1Pin, INPUT_PULLUP);
pinMode(Button2Pin, INPUT_PULLUP);
pinMode(Button3Pin, INPUT_PULLUP);
pinMode(WaterPumpPin, OUTPUT);
lcd.begin(16, 2); // Initialize the LCD with 16x2 characters
lcd.setCursor(0, 0);
lcd.print(" HOW MUCH WATER");
lcd.setCursor(0, 1);
lcd.print(" YOU WANT ");
}
void loop() {
if (digitalRead(Button1Pin) == LOW) {
startPump(9000); //100ml
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Filling water...");
lcd.setCursor(0, 1);
lcd.print(" 100ML ");
}
if (digitalRead(Button2Pin) == LOW) {
startPump(22500);//250ml
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Filling water...");
lcd.setCursor(0, 1);
lcd.print(" 250ML ");
}
if (digitalRead(Button3Pin) == LOW) {
startPump(45800);//500ml
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Filling water...");
lcd.setCursor(0, 1);
lcd.print(" 500ML ");
}
if (pumpRunning && (millis() - startTime >= pumpDuration)) {
stopPump();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" HOW MUCH WATER");
lcd.setCursor(0, 1);
lcd.print(" YOU WANT ");
}
}
void startPump(unsigned long duration) {
digitalWrite(WaterPumpPin, HIGH); // Turn on the water pump
pumpDuration = duration;
startTime = millis();
pumpRunning = true;
}
void stopPump() {
digitalWrite(WaterPumpPin, LOW); // Turn off the water pump
pumpRunning = false;
}