Using the delay vs millis to sequence relays

I hope this helps.

// Turn 5 relays on and off in sequence

/*
UNO Pin Setup
Pin 2 - Switch
Pin 6 - Relay 1 (IN1)
Pin 7 - Relay 2 (IN2)
Pin 8 - Relay 3 (IN3)
Pin 9 - Relay 4 (IN4)
Pin 10 - Relay 5 (IN5)
Pin 13 - Power on/off LED
*/

unsigned int Led13 = 13 ; // setup pin 13 for LED indicates button is active
unsigned int PRbutton2 = 2 ; // Setup pin 2 for PhotoResistor Button
unsigned int ButtonState = 0; // Value for Button State on pin 2
unsigned int RelaysOnState = 0; // Value for Relays On State
unsigned int PinArray[] = {6,7,8,9,10}; // PinArray for Relays
int x = 0; // Counter used in for loops
unsigned int DelayTime = 1000; // Time to delay while turning on Relays

void setup(){

pinMode(Led13, OUTPUT) ; //Turn off LED pin 13
digitalWrite (Led13, LOW) ;

pinMode(PRbutton2, INPUT); //setup pin 2 input for switch
digitalWrite (PRbutton2, LOW); // default low or 0

for (x=0;x<5;x++) { // Make all the declarations at once
pinMode(PinArray[x], OUTPUT);
} // End of For Loop
} // End of Setup Loop

// * * * * * * * * Start of Main Loop * * * * * * * * *
void loop() {
digitalWrite (Led13, HIGH) ; // Led13 is On when Button is active
ButtonState = digitalRead(PRbutton2); // Button Pushed
if (ButtonState == (1) && RelaysOnState == (0)); // Button Pushed and Relays off
{
OffToOn();
}
if (ButtonState == (1) && RelaysOnState == (1)); // Button Pushed and Relays on
{
OnToOff();
}

} // End of Main Loop

// * * * * * Subroutines * * * * *

void OffToOn()
{ // Start OffToOn Function
digitalWrite (Led13, LOW) ; // Turn Led off to indicate button is inactive
RelaysOnState = (1); // Set RelaysOnState to 1 to indicate Relays are in fact ON
for (x=0;x<5;x++) {
digitalWrite(PinArray[x], HIGH); // Turn on all relays with a one second delay in between
delay(DelayTime);
} // End OffToOn Function
}

void OnToOff()
{ // Start OnToOff Function
digitalWrite (Led13, LOW) ; // Turn Led off to indicate button is inactive
RelaysOnState = (0); // Set RelaysOnState to 0 to indicate Relays are in fact OFF
for (x=4;x>=0;x--) {
digitalWrite(PinArray[x], LOW); // Turn off all relays with a one second delay in between
delay(DelayTime);
}
} // End OnToOff Function

RWFiveRelayOnOff.ino (2.35 KB)