const int relayPin = 6;
const int buttonPins[] = {A1, A2, A3, A4, A5};
const int numButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);
int correctSequence[] = {1, 3, 2, 1, 5, 4, 2};
const int sequenceLength = sizeof(correctSequence) / sizeof(correctSequence[0]);
int inputIndex = 0;
unsigned long relayOnTime = 5000; // 5 seconds
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
for (int i = 0; i < numButtons; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
delay(50); // Debounce
while (digitalRead(buttonPins[i]) == LOW); // Wait for button release
delay(50); // Debounce
if (i + 1 == correctSequence[inputIndex]) {
inputIndex++;
if (inputIndex == sequenceLength) {
activateRelay();
inputIndex = 0; // Reset the inputIndex after successful activation
}
} else {
inputIndex = 0; // Reset the inputIndex if an incorrect button is pressed
}
}
}
}
void activateRelay() {
digitalWrite(relayPin, HIGH);
delay(relayOnTime);
digitalWrite(relayPin, LOW);
}