This circuit is designed to control eight 1-Channel 5V Relay Modules using an Arduino UNO microcontroller and a single pushbutton. When the pushbutton is pressed, each relay is activated sequentially for 150 seconds. The relays can be used to control various devices, such as lights or motors, that require higher power than the Arduino can provide directly.
/*
* This Arduino sketch controls 8 relays using a pushbutton. When the button
* is pressed, each relay is activated sequentially for 150 seconds.
*/
#define PUSHBUTTON_PIN 13
int relayPins[] = {11, 10, 9, 8, 7, 6, 5, 4};
void setup() {
pinMode(PUSHBUTTON_PIN, INPUT_PULLUP);
for (int i = 0; i < 8; i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], LOW);
}
}
void loop() {
if (digitalRead(PUSHBUTTON_PIN) == LOW) {
for (int i = 0; i < 8; i++) {
digitalWrite(relayPins[i], HIGH);
delay(150000); // Activate relay for 150 seconds
digitalWrite(relayPins[i], LOW);
}
}
}
Note: The code provided assumes that the pushbutton is connected to pin D13 and the relays are connected to pins D4 to D11. The INPUT_PULLUP
mode is used for the pushbutton, which means the button should be connected between the pin and ground. The relays are activated by setting the corresponding pin to HIGH
.