Arduino Based Home Automation
Arduino Based Home Automation
void setup() {
pinMode(8, OUTPUT); // Set pin 8 as an output for Relay 1
pinMode(9, OUTPUT); // Set pin 9 as an output for Relay 2
pinMode(10, OUTPUT); // Set pin 10 as an output for Relay 3
Serial.begin(9600); // Begin serial communication at 9600 baud
// Initialize all relays to be off
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
void loop() {
if (Serial.available()) {
val = Serial.read(); // Read the incoming byte
Serial.println(val); // Print the received value to the serial monitor
if (val == '1') {
digitalWrite(8, LOW); // Turn Relay 1 on
} else if (val == '2') {
digitalWrite(8, HIGH); // Turn Relay 1 off
} else if (val == '3') {
digitalWrite(9, LOW); // Turn Relay 2 on
} else if (val == '4') {
digitalWrite(9, HIGH); // Turn Relay 2 off
} else if (val == '5') {
digitalWrite(10, LOW); // Turn Relay 3 on
} else if (val == '6') {
digitalWrite(10, HIGH); // Turn Relay 3 off
}
}
}