nested timing sequence coding help

Newbie issue: I'm trying to write a sketch that turns on a Pump motor every 30 minutes "cycleInterval" (via a relay pin) and run the Pump for 5 minutes at a time. I'm able to get the 30 minute intervals just fine, however, the Pump runs for the entire 30 minutes when I only want it to run for 5 minutes and then shut off. I'm sure I'm making a rookie mistake somewhere in my code. Below is a snapshot, let me know if I should post the entire sketch.

// The Interval between turning on the pump
if (currentMillis - previousMillis > cycleInterval)
{
previousMillis = currentMillis;

// Turn on/off the Pump cycle
if (currentMillisPumpCycle - previousMillisPumpCycle > cyclePump)
{
previousMillisPumpCycle = currentMillisPumpCycle;

// Turn on/off the Pump
if (pumpState == LOW)
pumpState = HIGH;
else
pumpState = LOW;

// Turn on/off the LED indicator
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
}
}

Why are you nesting your 5 minute check inside your 30 minute check? The first if statement only runs once every 30 minutes, so the 5 minute check that is nested inside, only gets checked once every 30 minutes as well.

All you need to do inside the "once-every-30" code is set the previous time and turn on the relay. In a completely separate if statement, you should be checking if it's been 5 minutes since the previous time you set and turn off the relay.

Arrch:
Why are you nesting your 5 minute check inside your 30 minute check? The first if statement only runs once every 30 minutes, so the 5 minute check that is nested inside, only gets checked once every 30 minutes as well.

All you need to do inside the "once-every-30" code is set the previous time and turn on the relay. In a completely separate if statement, you should be checking if it's been 5 minutes since the previous time you set and turn off the relay.

Thank you, Arrch. I see what you're saying. How would you you write this part? I tried it but all it does is ignore my cyclePump argument and keeps the pump on for 30 minutes...

velocity101:
Thank you, Arrch. I see what you're saying. How would you you write this part? I tried it but all it does is ignore my cyclePump argument and keeps the pump on for 30 minutes...

Exactly how I phrased it in my last post.

You may find it beneficial to make sure you REALLY understand how millis() and timing works. Clearly you've looked at the Blink Without Delay example, but you should really play with it. Change stuff until you fully understand how it works. It's such a fundamental concept that only half knowing how it works and what it does is a doing yourself a great disservice.

I think this is exactly what I'm looking for as a guide! Thanks, Nick!