user57854: I have a functional sketch that I run on an Arduino Uno, the output controlling a fan module; I need another timer to run a 2nd fan and I would like to use another output on the Uno to do that rather than using another unit.
What my sketch does is as follows:

counts 15 minutes (interval_1)
starts the fan for 1 minute (interval_2)
starts another cycle.

What I need to do is to add another function that will start fan#2 for 15 sec (interval_3) when the cycle starts, using another output (relayPin_1), then stop.
So the flow will be:

counts 15 minutes (interval_1)
starts fan#1 for 60 sec (interval_2)
starts fan#2 for 15 sec (interval_3)
resets and starts another cycle.

Unfortunately, can't figure out how to insert the 2nd timer.
Sketch is below, if you have any ideas that would be much appreciated.
Thanks
const byte relayPin = 4;                           // fan#1 control on pin 4, 
const byte relayPin_1 = 7;                         // humidifier fan#2 control on pin 7,
const unsigned long interval_1 = 1000UL * 60,      // RUN timer, msec
                    interval_2 = 1000UL * 60 * 15, // OFF timer, msec
                    interval_3 = 1000UL * 15;      // Humidifier timer
unsigned long currentMillis, previousMillis = 0;

void setup() {
    // put your setup code here, to run once:
    pinMode(relayPin, OUTPUT);   // Output#1
    pinMode(relayPin_1, OUTPUT); //Output#2
    // relayPin_1 controls the humidifier's fan#2
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    // at startup, fan is ON for interval_1 duration
    currentMillis = millis() - previousMillis;
    if (currentMillis <= interval_1) {
        digitalWrite(relayPin, HIGH);    // fan ON
        digitalWrite(LED_BUILTIN, HIGH); // LED ON (blinking)
        delay(333 / 2);
        digitalWrite(LED_BUILTIN, LOW);   // LED Off
        delay(999);
    }

    // when interval_1 is reached, turn fan OFF for the duration of interval_2
    else if (currentMillis <= (interval_1 + interval_2)) {
        digitalWrite(relayPin, LOW);    // fan OFF
        digitalWrite(LED_BUILTIN, LOW); // led OFF
    }
    else {
        // reset the timer
        previousMillis = millis();
    }

}


Okay... I had time to play with it today; what it does:
it starts both fan#1 and fan#2, then stops fan#2 at (interval_1 + interval_2), but fan#1 continues running until the cycle ends.
Therefore: fan#1 runs for 35 sec, fan#2 runs for 15 sec, as it should; and the cycle is stopped for 30 sec as it should.
However, I can't make fan#1 to run for only 20 sec. as it is defined.

const byte relayPin = 4;   // recyrculation fan#1 control on pin 4, 
const byte relayPin_1 = 7; // humidifier fan#2 control on pin 7,
const unsigned long interval_1 = 1000UL * 20,    // RUN timer fan#1, msec
                    interval_2 = 1000UL * 15,    // RUN timer fan#2, msec
                    interval_3 = 1000UL * 30;    // OFF timer
unsigned long currentMillis, previousMillis = 0;

void setup() {
   // put your setup code here, to run once:
   pinMode(relayPin, OUTPUT); // Output#1
    pinMode(relayPin_1, OUTPUT); //Output#2
     pinMode(LED_BUILTIN, OUTPUT); }

void loop() {
// at startup, fan#1 & fan#2 are ON 
 currentMillis = millis() - previousMillis;
  if (currentMillis < interval_1) {
    digitalWrite(relayPin, HIGH);   // fan#1 ON
    digitalWrite(relayPin_1, HIGH); // fan#2 ON
     digitalWrite(LED_BUILTIN, HIGH); // builtin LED ON

 } else if (currentMillis < (interval_1 + interval_2)) {
    digitalWrite(relayPin_1, LOW); // fan#2 OFF

   // when (interval_1 + interval_2) is reached, turn fans OFF for the duration of interval_3
 } else if (currentMillis < (interval_1 + interval_2 + interval_3)) {
   digitalWrite(relayPin, LOW);      // fan#1 OFF
    digitalWrite(LED_BUILTIN, LOW); // led OFF

 } else {
   // reset the timer  
     previousMillis = millis(); }
 }


user2967: Assuming you get your logic straightened out, you should be able to add as many cases to your if statement as you want:
  if (currentMillis <= interval_1) {
      // Before end of interval 1, fan off.
  } else if (currentMillis <= (interval_1 + interval_2)) {
      // In interval 2, fan on
  } else if (currentMillis <= (interval_1 + interval_2 + interval_3 )) {
      // In interval 3, fan2 on
  } else {
      // Turn everything off
      // reset the timer  
  }


57854: <p>I have a functional sketch that I run on an Arduino Uno, the output controlling a fan module; I need another timer to run a 2nd fan and I would like to use another output on the Uno to do that rather than using another unit.</p>

<p>What my sketch does is as follows:</p>

<ul>
<li>counts 15 minutes (interval_1)</li>
<li>starts the fan for 1 minute (interval_2)</li>
<li>starts another cycle.</li>
</ul>

<p>What I need to do is to add another function that will start fan#2 for 15 sec (interval_3) when the cycle starts, using another output (relayPin_1), then stop.</p>

<p>So the flow will be:</p>

<ul>
<li>counts 15 minutes (interval_1)</li>
<li>starts fan#1 for 60 sec (interval_2)</li>
<li>starts fan#2 for 15 sec (interval_3)</li>
<li>resets and starts another cycle.</li>
</ul>

<p>Unfortunately, can't figure out how to insert the 2nd timer.</p>

<p>Sketch is below, if you have any ideas that would be much appreciated.</p>

<p>Thanks</p>

<pre><code>const byte relayPin = 4;                           // fan#1 control on pin 4, 
const byte relayPin_1 = 7;                         // humidifier fan#2 control on pin 7,
const unsigned long interval_1 = 1000UL * 60,      // RUN timer, msec
                    interval_2 = 1000UL * 60 * 15, // OFF timer, msec
                    interval_3 = 1000UL * 15;      // Humidifier timer
unsigned long currentMillis, previousMillis = 0;

void setup() {
    // put your setup code here, to run once:
    pinMode(relayPin, OUTPUT);   // Output#1
    pinMode(relayPin_1, OUTPUT); //Output#2
    // relayPin_1 controls the humidifier's fan#2
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    // at startup, fan is ON for interval_1 duration
    currentMillis = millis() - previousMillis;
    if (currentMillis &lt;= interval_1) {
        digitalWrite(relayPin, HIGH);    // fan ON
        digitalWrite(LED_BUILTIN, HIGH); // LED ON (blinking)
        delay(333 / 2);
        digitalWrite(LED_BUILTIN, LOW);   // LED Off
        delay(999);
    }

    // when interval_1 is reached, turn fan OFF for the duration of interval_2
    else if (currentMillis &lt;= (interval_1 + interval_2)) {
        digitalWrite(relayPin, LOW);    // fan OFF
        digitalWrite(LED_BUILTIN, LOW); // led OFF
    }
    else {
        // reset the timer
        previousMillis = millis();
    }

}
</code></pre>

<hr>

<p>Okay... I had time to play with it today; what it does:
it starts both fan#1 and fan#2, then stops fan#2 at (interval_1 + interval_2), but fan#1 continues running until the cycle ends.
Therefore: fan#1 runs for 35 sec, fan#2 runs for 15 sec, as it should; and the cycle is stopped for 30 sec as it should.
However, I can't make fan#1 to run for only 20 sec. as it is defined.</p>

<pre><code>
const byte relayPin = 4;   // recyrculation fan#1 control on pin 4, 
const byte relayPin_1 = 7; // humidifier fan#2 control on pin 7,
const unsigned long interval_1 = 1000UL * 20,    // RUN timer fan#1, msec
                    interval_2 = 1000UL * 15,    // RUN timer fan#2, msec
                    interval_3 = 1000UL * 30;    // OFF timer
unsigned long currentMillis, previousMillis = 0;

void setup() {
   // put your setup code here, to run once:
   pinMode(relayPin, OUTPUT); // Output#1
    pinMode(relayPin_1, OUTPUT); //Output#2
     pinMode(LED_BUILTIN, OUTPUT); }

void loop() {
// at startup, fan#1 &amp; fan#2 are ON 
 currentMillis = millis() - previousMillis;
  if (currentMillis &lt; interval_1) {
    digitalWrite(relayPin, HIGH);   // fan#1 ON
    digitalWrite(relayPin_1, HIGH); // fan#2 ON
     digitalWrite(LED_BUILTIN, HIGH); // builtin LED ON

 } else if (currentMillis &lt; (interval_1 + interval_2)) {
    digitalWrite(relayPin_1, LOW); // fan#2 OFF

   // when (interval_1 + interval_2) is reached, turn fans OFF for the duration of interval_3
 } else if (currentMillis &lt; (interval_1 + interval_2 + interval_3)) {
   digitalWrite(relayPin, LOW);      // fan#1 OFF
    digitalWrite(LED_BUILTIN, LOW); // led OFF

 } else {
   // reset the timer  
     previousMillis = millis(); }
 }
</code></pre>
 2967: <p>Assuming you get your logic straightened out, you should be able to add as many cases to your if statement as you want:</p>

<pre><code>  if (currentMillis &lt;= interval_1) {
      // Before end of interval 1, fan off.
  } else if (currentMillis &lt;= (interval_1 + interval_2)) {
      // In interval 2, fan on
  } else if (currentMillis &lt;= (interval_1 + interval_2 + interval_3 )) {
      // In interval 3, fan2 on
  } else {
      // Turn everything off
      // reset the timer  
  }
</code></pre>
