const int relayWindowPin = 4; // Digital pin for window relay
const int relayDoorPin = 5; // Digital pin for door relay
const int buttonPin = 6; // Digital pin for control button
const int statusLedPin = 7; // Digital pin for status LED
void setup() {
pinMode(relayWindowPin, OUTPUT);
pinMode(relayDoorPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(statusLedPin, OUTPUT); // Set status LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
// Read the state of the control button
bool buttonState = digitalRead(buttonPin);
// Simulate opening or closing the window and door based on the button state
if (buttonState == LOW) {
digitalWrite(relayWindowPin, HIGH); // Turn on the relay for window
digitalWrite(relayDoorPin, HIGH); // Turn on the relay for door
Serial.println("Door and window open!");
} else {
digitalWrite(relayWindowPin, LOW); // Turn off the relay for window
digitalWrite(relayDoorPin, LOW); // Turn off the relay for door
Serial.println("Door and window closed!");
}
// Check if both the window and door are open
bool doorOpen = digitalRead(relayDoorPin) == HIGH;
bool windowOpen = digitalRead(relayWindowPin) == HIGH;
// Turn on the status LED if both window and door are open
digitalWrite(statusLedPin, doorOpen && windowOpen ? HIGH : LOW);
delay(100); // Adjust the delay as needed to debounce the button
}