#include <LiquidCrystal.h>
#define WATER_RELAY_PIN 2
#define HEATER_RELAY_PIN 3
#define LED_PIN 4
#define START_STOP_SWITCH_PIN 5
#define MODE_SWITCH_PIN 6
#define BUZZER_PIN 7
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
// Define wash modes
String washModes[] = {"Gentle", "Normal", "Heavy"};
int selectedMode = 0;
// Define wash time in minutes
int washTime = 15; // Default wash time
bool washingInProgress = false;
void setup() {
pinMode(WATER_RELAY_PIN, OUTPUT);
pinMode(HEATER_RELAY_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(START_STOP_SWITCH_PIN, INPUT_PULLUP);
pinMode(MODE_SWITCH_PIN, INPUT_PULLUP);
pinMode(BUZZER_PIN, OUTPUT);
lcd.begin(16, 2);
lcd.print("Washing Machine");
lcd.setCursor(0, 1);
lcd.print("Status: IDLE");
}
void loop() {
// Check if the start/stop switch is pressed
if (digitalRead(START_STOP_SWITCH_PIN) == LOW) {
if (!washingInProgress) {
// Start the washing process
startWashing();
} else {
// Stop the washing process
stopWashing();
}
// Wait for switch release to avoid multiple triggers
while (digitalRead(START_STOP_SWITCH_PIN) == LOW) {}
}
// Check if the mode switch is pressed
if (digitalRead(MODE_SWITCH_PIN) == LOW) {
// Cycle through different wash modes
selectedMode = (selectedMode + 1) % 3;
// Update LCD to display the selected mode
lcd.clear();
lcd.print("Mode: " + washModes[selectedMode]);
// Wait for switch release to avoid multiple triggers
while (digitalRead(MODE_SWITCH_PIN) == LOW) {}
}
}
void startWashing() {
washingInProgress = true;
lcd.clear();
lcd.print("Washing Machine");
lcd.setCursor(0, 1);
lcd.print("Status: RUNNING");
// Simulate filling water
digitalWrite(WATER_RELAY_PIN, HIGH);
tone(BUZZER_PIN, 1500); // Change buzzer tone for filling water
delay(2000); // Simulate water filling process
noTone(BUZZER_PIN); // Stop the buzzer
digitalWrite(WATER_RELAY_PIN, LOW);
// Simulate heating water
digitalWrite(HEATER_RELAY_PIN, HIGH);
tone(BUZZER_PIN, 2000); // Change buzzer tone for heating water
delay(3000); // Simulate heating process
noTone(BUZZER_PIN); // Stop the buzzer
digitalWrite(HEATER_RELAY_PIN, LOW);
// Simulate washing
digitalWrite(LED_PIN, HIGH); // Turn on LED
tone(BUZZER_PIN, 2500); // Change buzzer tone for washing
delay(5000); // Simulate washing process
noTone(BUZZER_PIN); // Stop the buzzer
digitalWrite(LED_PIN, LOW); // Turn off LED
lcd.clear();
lcd.print("Washing Machine");
lcd.setCursor(0, 1);
lcd.print("Status: IDLE");
washingInProgress = false;
}
void stopWashing() {
lcd.clear();
lcd.print("Washing Machine");
lcd.setCursor(0, 1);
lcd.print("Status: STOPPED");
digitalWrite(WATER_RELAY_PIN, LOW); // Stop filling water
digitalWrite(HEATER_RELAY_PIN, LOW); // Stop heating water
digitalWrite(LED_PIN, LOW); // Turn off LED
washingInProgress = false;
}