Running multiple 6v motors simultanoeusly - Newbie question

I am working on a project that I thought would be simple, and probably is, but can't find the right approach given my limited knowledge and experience. I want to run 6-8 small 6v motors (via relays) simultaneously in an outdoor animation display. I would like each motor to turn on and off several times and for different durations during each cycle of the loop. Each motor will run a slightly different on/off routine but all mostly running at the same time. I would envision the entire cycle of the loop to last 2-3 minutes then repeat indefinitely. I easily can get the individual motors to turn on and off as I want using the delay function. But since I want all motors to be running at the same time, I can't use delay how do I program this so each motor is running its own routine simultaneously?

But since I want all motors to be running at the same time, I can't use delay how do I program this so each motor is running its own routine simultaneously?

Forget the Arduino, for a moment. You have a watch, a pad of paper and a pencil. How would YOU turn the relays on an off at the right time.

Periodically, note the time. Compare that time with when each relay was turned on or off. If it is time to toggle the relay, do so.

The millis() function is your watch. The variables in the sketch are your pencil and paper.

I can't use delay

Hint:- in the examples folder of the arduino is a sketch called "Blink without delay"

OK perhaps I'm not being clear or am attempting too much project for my coding knowledge and just can't see the answers your providing. So I went through Blink w/o Delay example and while I see how it will make the motor change state, what I don't understand is how to make that motor do something different from the last time each time it starts or stops.

As a more specific example of what I'm trying to do - say the motor using pin 2 has a three step routine that says {Turn on 15 sec - Turn off 30 sec - Turn on 2 sec - Turn off 5 sec - Turn on 2 sec - Turn off 60 sec (REPEAT)}. Simultaneously (or nearly so) the motor in pin 3 goes through a slightly different routine say Turns on 30 sec - Turn off 30 sec - Turn on 5 sec - Turn off 10 sec - Turn on 2 sec - Turn off 40 sec (REPEAT). The other 4 or 5 motors would have similar start stop routines all running concurrently.

In this instance, I'm not married to any particular routine, timing or start stop length. I simply want 6-8 motors randomly turning on and off without the real impression of a pattern or sequence.

Use blink without delay and some flags:

void loop(){
currentMillis = millis();
if (currentMillis - previousMillis >=1000){  // has 1 second elapsed?
previousMillis =  current Millis;  // reset time for the next second
//check the state of the motors
  if (motor1_flag == 1) {    //1 = running, 0 = stopped
  motor1_seconds = motor1_seconds +1;
         if (motor1_seconds == motor1_timelimit){
         motor1_flag = 0; // indicates motor1 is off
        // do what you need to stop the motor
         // and set motor1_timelimit to next value
         }
   if (motor1_flag == 0) {  1 = running, 0 = stopped
   motor1_seconds = motor1_seconds +1;
         if (motor1_seconds == motor1_timelimit){
         motor1_flag = 1; // turn motor1 on
        // do what you need to turn motor1 on
         // and set motor1_timelimit to next value
         }
}  // check  on these, might be mismatched
}
}

Repeat for the other motors. Make sense?

make sence.

if (motor1_flag == 1) { //1 = running, 0 = stopped

This is not meant to encourage you to define motor2_flag, motor3_flag, etc.

You have 6 motors. 6 flags, 6 start times, 6 stop times, 6 on intervals, 6 off intervals, etc. will get ugly quick.

Arrays are needed. An array of flags, an array of start times, an array of stop times, etc. would be much easier to iterate over in a for loop.

I like the "1 concept at a time approach" :) Repeat the code 6 times, change the variable names. Easy to follow.

Hammer it out hardware designer approach vs the more elegant software designer approach 8)

Repeat the code 6 times, change the variable names.

Make sure you change everything you are supposed to, and nothing that you are not supposed to. If you find a problem, fix it 6 times.

I guess we'll just have to agree to disagree.

Fair enough.