#define RELAY1_PIN 5
#define RELAY2_PIN 18
#define LED_PIN 23
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
Serial.println("Smart Home Control Initialized");
// Set pin modes
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
// Start with all devices off
digitalWrite(RELAY1_PIN, LOW);
digitalWrite(RELAY2_PIN, LOW);
digitalWrite(LED_PIN, LOW);
}
void loop() {
// Check if data is available from Serial Monitor
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
command.trim(); // Remove any extra spaces or newlines
// Process the command
if (command == "RELAY1 ON") {
digitalWrite(RELAY1_PIN, HIGH);
Serial.println("Relay 1 is ON");
} else if (command == "RELAY1 OFF") {
digitalWrite(RELAY1_PIN, LOW);
Serial.println("Relay 1 is OFF");
} else if (command == "RELAY2 ON") {
digitalWrite(RELAY2_PIN, HIGH);
Serial.println("Relay 2 is ON");
} else if (command == "RELAY2 OFF") {
digitalWrite(RELAY2_PIN, LOW);
Serial.println("Relay 2 is OFF");
} else if (command == "LED ON") {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED is ON");
} else if (command == "LED OFF") {
digitalWrite(LED_PIN, LOW);
Serial.println("LED is OFF");
} else {
Serial.println("Unknown command. Use: RELAY1 ON, RELAY1 OFF, RELAY2 ON, RELAY2 OFF, LED ON, LED OFF");
}
}
}