0% found this document useful (0 votes)
9 views

Arduino Based Home Automation

Uploaded by

naiknishant48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Arduino Based Home Automation

Uploaded by

naiknishant48
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

char val;

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
}
}
}

You might also like