const int numButtons = 7; // Define the number of buttons
const int lightPins[numButtons] = {14, 15, 16, 17, 18, 19, 20}; // Assign pins for each button
const int buttonPins[numButtons] = {2, 3, 4, 5, 6, 7, 8}; // Assign pins for each light
const int power_btn=9;
const int relay_bulb=37;
const int relayPins[numButtons] = {23,25,27,29,31,33,35}; // relay pins
int buttonStates[numButtons]; // Array to store the state of each button
int numButtonsPressed = 0; // Count of the number of buttons currently pressed
int x=0;
int bulb_time=5; // you can change the time for indicator bulb relay in seconds. 120 seconds = 2 minutes
void setup() {
// Initialize button pins as inputs
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(power_btn,INPUT_PULLUP);
// Initialize light pins as outputs
for (int i = 0; i < numButtons; i++) {
pinMode(lightPins[i], OUTPUT);
pinMode(relayPins[i], OUTPUT);
}
pinMode(relay_bulb, OUTPUT);
}
void loop() {
// Read the state of each button and store it in the buttonStates array
if(digitalRead(power_btn)==LOW && x==0){
for (int i = 0; i < numButtons; i++) {
buttonStates[i] = digitalRead(buttonPins[i]);
}
// Count the number of buttons that are currently pressed
numButtonsPressed = 0;
for (int i = 0; i < numButtons; i++) {
if (buttonStates[i] == LOW) {
numButtonsPressed++;
}
}
// Turn on the corresponding lights based on the number of buttons pressed
for (int i = 0; i < numButtonsPressed; i++) {
digitalWrite(lightPins[i], HIGH);
digitalWrite(relayPins[i], HIGH);
digitalWrite(relay_bulb, HIGH);
}
// Turn off the remaining lights
for (int i = numButtonsPressed; i < numButtons; i++) {
digitalWrite(lightPins[i], LOW);
digitalWrite(relayPins[i], LOW);
}
delay(1000); // you can change the time for solenoid relays here delay(milliseconds).
for(int i=0; i <7; i++){
digitalWrite(relayPins[i], LOW);
}
delay((bulb_time-1)*1000);
digitalWrite(relay_bulb, LOW);
x=1;
}
else if(digitalRead(power_btn)==HIGH){
for (int i = 0; i < 7; i++) {
digitalWrite(lightPins[i], LOW);
digitalWrite(relayPins[i], LOW);
x=0;
}
}
}