Help with if statements

how can i get this to work with my script. without cutting off the other half of the loop?

 if (digitalRead(fanrelay) != HIGH)
  {
    delay(1);
    Serial.println ("fan relay on");
    fancounter = fancounter + 1;
    Serial.println(fancounter);
    {
      while (digitalRead(fanrelay) != HIGH)
        delay(1);
    }
  }
    if (digitalRead(pumprelay) != HIGH)
  {
    delay(1);
    Serial.println ("pump relay on");
    pumpcounter = pumpcounter + 1;
    Serial.println(pumpcounter);
    {
      while (digitalRead(pumprelay) != HIGH)
        delay(1);
    }
  }
     if (digitalRead(drainrelay) != HIGH)
  {
    delay(1);
    Serial.println ("drain relay on");
    draincounter = draincounter + 1;
    Serial.println(draincounter);
    {
      while (digitalRead(drainrelay) != HIGH)
        delay(1);
    }
  }

notsolowki:
okay so i added this to the void setup() " interval2 = pumpoffInterval;"
and that took care of it? i wish i knew exactly why.?!? now i guess its time to get my counter to work. i know each relay has its own interval. the fan is interval and the pump is interval2

Because in your original code you had
unsigned long interval2=0;
and it was not set to more. So as soon as the code got to
if (currentMillis - previousMillis > interval2)
it was true and executed turning the pump on. When you set intervat2 in setup() to something larger it waits for the time to expire before it starts the pump.
But I noticed another bug in your code: you need two previousMillis variables - one for pump and one for fan. This way it will not work as I think you want it to work (it will only turn on and off the fan and will never turn on the pump because the fan part will always update previousMillis before pump is ready to start...)
EDIT:

notsolowki:
how can i get this to work with my script. without cutting off the other half of the loop?

while (digitalRead(drainrelay) != HIGH) delay(1);
is evil. It stucks the program until the drainrelay goes HIGH. But since the program is stuck in this endless loop it will never get to the part where it will do it. You need remove this part and save to a variable you already reported this happened ("set a flag"). Then in each main loop iteration you check if drainrelay went HIGH. If so "clear the flag" - write the variable to its "idle" value.

this is what my setup part of the code looks like now,

void setup() {
  interval = offInterval;
  interval2 = pumpoffInterval; //new
  pinMode (drainbutton, INPUT_PULLUP); //DRAIN ACTIVATION PIN
  pinMode (fanrelay, OUTPUT); //FAN POWER RELAY
  pinMode (pumprelay, OUTPUT); //WATER PRESSURE PUMP
  pinMode (drainrelay, OUTPUT); //DRAIN SOLENOID POWER RELAY
  digitalWrite(pumprelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(fanrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainbutton, HIGH); //SET INITAL BUTTON STATE
  Serial.begin(9600);
  Serial.print("Ready");
}

i wish i could just get the button counter to work. i have it sending message over serial through an esp8266 to a telnet session. to relay the data to me. i have no practical reason to do this but it just interests me.

Here's a way to count how many times the pump comes on:

 //DRAIN CYCLE
  currentTime = millis();
  previousdrainbuttonState = currentdrainbuttonState;
  currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == LOW)//ASK WHATS THE STATE OF THE Pump
    {
    Serial.println ("pump relay on");
    pumpcounter = pumpcounter + 1;
    Serial.println(pumpcounter);

    }
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    startTime = millis();
    digitalWrite(drainrelay, LOW);//TURN IT ON
  }

  if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
  {
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }

Checks state change as suggested earlier.

i have this section for the pump millis.

unsigned long interval2 = 0;
unsigned long pumppreviousMillis = 0;
unsigned long pumponInterval = 1000; // spray on time 26 SECONDS
unsigned long pumpoffInterval = 1000; // sprayer off time 1.8 HRS

on the pump sysle this is how i have it,

if (currentMillis - previousMillis > interval2) {
    pumppreviousMillis = currentMillis;
    if (pumprelayState == HIGH) { //IF ITS OFF
      pumprelayState = LOW; // TURN IT ON

      interval2 = pumponInterval; //ASK HOW LONG TO TURN IT ON
    }

    else {
      pumprelayState = HIGH; //OTHERWISE TURN IT OFF
      interval2 = pumpoffInterval; //ASK HOW LONG TO TURN IT OFF
    }
    digitalWrite(pumprelay, pumprelayState); //DEBOUNCE
    delay(50);
  }

one thing i dont understand is

]if (currentMillis - previousMillis > interval2) {
    pumppreviousMillis = currentMillis;

how is this going to work along side the fan relay millis. for the pump if i change (currentMillis - previousMillis > interval2) { to (currentMillis - pumppreviousMillis > interval2) { the pump timer dont work right. im not sure if it will work right at all like your saying. thankyou for helping me

wildbill:
Here's a way to count how many times the pump comes on:

 //DRAIN CYCLE

currentTime = millis();
  previousdrainbuttonState = currentdrainbuttonState;
  currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == LOW)//ASK WHATS THE STATE OF THE Pump
    {
    Serial.println ("pump relay on");
    pumpcounter = pumpcounter + 1;
    Serial.println(pumpcounter);

}
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    startTime = millis();
    digitalWrite(drainrelay, LOW);//TURN IT ON
  }

if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
  {
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }



Checks state change as suggested earlier.

thankyou soo much for this. now that i have a working script i can try to learn more about the way it functions.

As hinted at above, This:

if (currentMillis - previousMillis > interval2) {

Should probably be:

if (currentMillis - pumppreviousMillis > interval2) {

It's probably worth renaming previousMillis to fanpreviousMillis too.

i know that what i thought too, but when i change it to if (currentMillis - pumppreviousMillis > interval2) {
the pump timer dont work.?!?!

i do notice though that if i set both relays to kick on at 500ms they do not kick on right. they dont need to switch like that, but it just means something must not be right but i dont know why i cant change previousmillis to pumppreviousmillis

Time to post your latest version then.

sure thing, one thing i do want to point out. is to make it easier for me wiring wise i set 2 pins as A1

//READ ONLY BUTTON CONFIGURATION
const int pumprelay = A1;
const int drainbutton = A1;
const int fanrelay = A0;
const int drainrelay = A4;

//INITAL PINSTATES
int fanlastState = HIGH;
int draincounter = 0;
int pumpcounter = 0;
int fancounter = 0;
int drainrelayState = HIGH;
int fanrelayState = HIGH;
int pumprelayState = HIGH;
int drainbuttonState = HIGH;

//FAN ON/OFF CYCLE

unsigned long previousMillis = 0; //
unsigned long interval = 0; //
unsigned long onInterval = 138000UL; //  FAN ON TIME 2.3 MINUTES
unsigned long offInterval = 1800000UL; // FAN OFF TIME 30 MINUTES

//PUMP ON/OFF CYCLE
unsigned long interval2 = 0;
unsigned long pumppreviousMillis = 0;
unsigned long pumponInterval = 36000UL; // spray on time 26 SECONDS
unsigned long pumpoffInterval = 6480000UL; // sprayer off time 1.8 HRS

//DRAIN RELAY ON TIME
unsigned long startTime;
unsigned long currentTime;
unsigned long period = 2000; //DRAIN OPEN TIME
int previousdrainbuttonState = HIGH;
int currentdrainbuttonState = HIGH;


void setup() {
  interval = offInterval;
  interval2 = pumpoffInterval;
  pinMode (drainbutton, INPUT_PULLUP); //DRAIN ACTIVATION PIN
  pinMode (fanrelay, OUTPUT); //FAN POWER RELAY
  pinMode (pumprelay, OUTPUT); //WATER PRESSURE PUMP
  pinMode (drainrelay, OUTPUT); //DRAIN SOLENOID POWER RELAY
  digitalWrite(pumprelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(fanrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainbutton, HIGH); //SET INITAL BUTTON STATE
  Serial.begin(9600);
  Serial.print("Ready");
}

void loop() {
  
  unsigned long currentMillis = millis();
 
  //FAN CYCLE
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    if (fanrelayState == HIGH) { //IF ITS OFF
      fanrelayState = LOW; // THEN TURN ON
      interval = onInterval; // ASK HOW LONG TO STAY ON
    }
    else {
      fanrelayState = HIGH; // OTHERWISE OFF
      interval = offInterval; //ASK HOW LONG TO STAY OFF
    }
    digitalWrite(fanrelay, fanrelayState); //UPDATE STATUS OF FAN
  }
  
//PUMP CYCLE
  
   if (currentMillis - previousMillis > interval2) {
    pumppreviousMillis = currentMillis;
    if (pumprelayState == HIGH) { //IF ITS OFF
      pumprelayState = LOW; // TURN IT ON

      interval2 = pumponInterval; //ASK HOW LONG TO TURN IT ON
    }

    else {
      pumprelayState = HIGH; //OTHERWISE TURN IT OFF
      interval2 = pumpoffInterval; //ASK HOW LONG TO TURN IT OFF
    }
    digitalWrite(pumprelay, pumprelayState); //DEBOUNCE
    delay(50);
  }
  
  //DRAIN CYCLE
  currentTime = millis();
  previousdrainbuttonState = currentdrainbuttonState;
  currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON

  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    startTime = millis();
    digitalWrite(drainrelay, LOW);//TURN IT ON
  }

  if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
  {
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }


}

I made the change to use pumppreviousMillis, added some serial.prints, reduced your intervals substantially and tried it out. Both pump and fan worked.

There is a problem though, the drain doesn't stay on. this was the fix:

  if (((millis() - StartTime) >= DrainPeriod)&& digitalRead(drainrelay)==LOW) //ASK HOW LONG TO STAY ON
  {
    Serial.println("Drain stop");
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }

notsolowki:
sure thing, one thing i do want to point out. is to make it easier for me wiring wise i set 2 pins as A1

//READ ONLY BUTTON CONFIGURATION

const int pumprelay = A1;
const int drainbutton = A1;
const int fanrelay = A0;
const int drainrelay = A4;

//INITAL PINSTATES
int fanlastState = HIGH;
int draincounter = 0;
int pumpcounter = 0;
int fancounter = 0;
int drainrelayState = HIGH;
int fanrelayState = HIGH;
int pumprelayState = HIGH;
int drainbuttonState = HIGH;

//FAN ON/OFF CYCLE

unsigned long previousMillis = 0; //
unsigned long interval = 0; //
unsigned long onInterval = 138000UL; //  FAN ON TIME 2.3 MINUTES
unsigned long offInterval = 1800000UL; // FAN OFF TIME 30 MINUTES

//PUMP ON/OFF CYCLE
unsigned long interval2 = 0;
unsigned long pumppreviousMillis = 0;
unsigned long pumponInterval = 36000UL; // spray on time 26 SECONDS
unsigned long pumpoffInterval = 6480000UL; // sprayer off time 1.8 HRS

//DRAIN RELAY ON TIME
unsigned long startTime;
unsigned long currentTime;
unsigned long period = 2000; //DRAIN OPEN TIME
int previousdrainbuttonState = HIGH;
int currentdrainbuttonState = HIGH;

void setup() {
 interval = offInterval;
 interval2 = pumpoffInterval;
 pinMode (drainbutton, INPUT_PULLUP); //DRAIN ACTIVATION PIN
 pinMode (fanrelay, OUTPUT); //FAN POWER RELAY
 pinMode (pumprelay, OUTPUT); //WATER PRESSURE PUMP
 pinMode (drainrelay, OUTPUT); //DRAIN SOLENOID POWER RELAY
 digitalWrite(pumprelay, HIGH); //SET INITAL RELAY STATE
 digitalWrite(fanrelay, HIGH); //SET INITAL RELAY STATE
 digitalWrite(drainrelay, HIGH); //SET INITAL RELAY STATE
 digitalWrite(drainbutton, HIGH); //SET INITAL BUTTON STATE
 Serial.begin(9600);
 Serial.print("Ready");
}

void loop() {
 
 unsigned long currentMillis = millis();

//FAN CYCLE
 if (currentMillis - previousMillis > interval) {
   previousMillis = currentMillis;
   if (fanrelayState == HIGH) { //IF ITS OFF
     fanrelayState = LOW; // THEN TURN ON
     interval = onInterval; // ASK HOW LONG TO STAY ON
   }
   else {
     fanrelayState = HIGH; // OTHERWISE OFF
     interval = offInterval; //ASK HOW LONG TO STAY OFF
   }
   digitalWrite(fanrelay, fanrelayState); //UPDATE STATUS OF FAN
 }
 
//PUMP CYCLE
 
  if (currentMillis - previousMillis > interval2) {
   pumppreviousMillis = currentMillis;
   if (pumprelayState == HIGH) { //IF ITS OFF
     pumprelayState = LOW; // TURN IT ON

interval2 = pumponInterval; //ASK HOW LONG TO TURN IT ON
   }

else {
     pumprelayState = HIGH; //OTHERWISE TURN IT OFF
     interval2 = pumpoffInterval; //ASK HOW LONG TO TURN IT OFF
   }
   digitalWrite(pumprelay, pumprelayState); //DEBOUNCE
   delay(50);
 }
 
 //DRAIN CYCLE
 currentTime = millis();
 previousdrainbuttonState = currentdrainbuttonState;
 currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON

if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
 {
   startTime = millis();
   digitalWrite(drainrelay, LOW);//TURN IT ON
 }

if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
 {
   digitalWrite(drainrelay, HIGH); //DEBOUNCE
   delay(50);
 }

}

You still have this wrong:

if (currentMillis - previousMillis > interval2) {
pumppreviousMillis = currentMillis;

you need to use pumppreviousMillis in the if condition.

It is OK that both pins are A1 in this application. In fact it is "clever". When you decide drainbutton should not be driven by pumprelay but from something else (i.e. real button) you can simply set it on another pin and everything will work provided you wrote your code properly.

sorry guys i fell asleep lol. i woke up this morning and the fan was the only thing that was cycling. i changed previousmillis to pumprpeviousmillis and actually watched the relay leds and your right it does work. i think its because i was listening for the relay click but the drain was staying open because its duration was longer than any other duration so it just stayed on and i mistook that for a bug. and serial print is working. i wondered why it didnt count with the button? well thats because millis is the only thing that activates the count, lol noob moment. thanks for all the help guys. sometime today i would like to try to convert pump time on in ms to liter of water per minute and have it give me an estimated amount of water output. thanks again everyone for being patient with me.

hi everyone, i am having another problem with my code. the problem im having is when i add the the bottom part of the code "MIST CIRCULATION AFTER PUMP OFF" my fan relays come on the first time properly, then the second time they come on about half as long. then eventually the relay for the fan just kicks on and off really fast. in my serial console i get "pump cycle complete" a whole bunch of times. can someone point out the bug please, if i remove the whole part of the code "MIST CIRCULATION AFTER PUMP OFF" then it work properly. thank you

//READ ONLY BUTTON CONFIGURATION
const int pumprelay = A1;
const int drainbutton = A1;
const int fanrelay = A0;
const int drainrelay = A4;

//INITAL PINSTATES
int fanlastState = HIGH;
int draincounter = 0;
int pumpcounter = 0;
int fancounter = 0;
int drainrelayState = HIGH;
int fanrelayState = HIGH;
int pumprelayState = HIGH;
int drainbuttonState = HIGH;

//FAN ON/OFF CYCLE
unsigned long previousMillis = 0; //
unsigned long interval = 0; //
unsigned long onInterval = 6000; //  FAN ON TIME 5 MINUTES 240000UL
unsigned long offInterval = 10000; // FAN OFF TIME 22 MINUTES 1320000UL

//PUMP ON/OFF CYCLE
unsigned long interval2 = 0;
unsigned long pumppreviousMillis = 0;
unsigned long pumponInterval = 36000UL; // spray on time 26 SECONDS 36000UL
unsigned long pumpoffInterval = 6480000UL; // sprayer off time 1.8 HRS 6480000UL

//DRAIN RELAY ON TIME
unsigned long startTime;
unsigned long currentTime;
unsigned long period = 4000; //DRAIN OPEN TIME
int previousdrainbuttonState = HIGH;
int currentdrainbuttonState = HIGH;

//MIST CIRUATION CONTROLL AFTER PUMPOFF
unsigned long fanstartTime;
unsigned long fancurrentTime;
unsigned long fanperiod = 30000 ; //FAN CIRCULATE ON TIME
int fanpreviousrelayState = HIGH;
int fancurrentrelayState = HIGH;

void setup() {
  interval = offInterval;
  interval2 = pumpoffInterval;
  pinMode (drainbutton, INPUT_PULLUP); //DRAIN ACTIVATION PIN
  pinMode (fanrelay, OUTPUT); //FAN POWER RELAY
  pinMode (pumprelay, OUTPUT); //WATER PRESSURE PUMP
  pinMode (drainrelay, OUTPUT); //DRAIN SOLENOID POWER RELAY
  digitalWrite(pumprelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(fanrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainbutton, HIGH); //SET INITAL BUTTON STATE
  Serial.begin(9600);
  Serial.print("Ready");
}

void loop() {

  unsigned long currentMillis = millis();

  //FAN CYCLE
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    if (fanrelayState == HIGH) { //IF ITS OFF
      fanrelayState = LOW; // THEN TURN ON

      interval = onInterval; // ASK HOW LONG TO STAY ON
      Serial.println ("fan relay on");
      fancounter = fancounter + 1;
      Serial.println(fancounter);
    }
    else {
      fanrelayState = HIGH; // OTHERWISE OFF
      interval = offInterval; //ASK HOW LONG TO STAY OFF
    }
    digitalWrite(fanrelay, fanrelayState); //UPDATE STATUS OF FAN
  }

  //PUMP CYCLE

  if (currentMillis - pumppreviousMillis > interval2) {
    pumppreviousMillis = currentMillis;
    if (pumprelayState == HIGH) { //IF ITS OFF

      pumprelayState = LOW; // TURN IT ON
      digitalWrite(fanrelay, LOW);
      interval2 = pumponInterval; //ASK HOW LONG TO TURN IT ON
      Serial.println ("pump relay on");
      pumpcounter = pumpcounter + 1;
      Serial.println(pumpcounter);

    }

    else {
      digitalWrite(fanrelay, HIGH);
      pumprelayState = HIGH; //OTHERWISE TURN IT OFF
      interval2 = pumpoffInterval; //ASK HOW LONG TO TURN IT OFF
    }

    digitalWrite(pumprelay, pumprelayState); //DEBOUNCE
    delay(50);


  }
  //DRAIN CYCLE
  currentTime = millis();
  previousdrainbuttonState = currentdrainbuttonState;
  currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    startTime = millis();
    digitalWrite(drainrelay, LOW);//TURN IT ON
    Serial.println ("drain relay on");
    draincounter = draincounter + 1;
    Serial.println(draincounter);
  }

  if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
  {
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }


  //MIST CIRCULTION AFTER PUMP OFF //HAVING PROBLEMS\\\
  fancurrentTime = millis();
  fanpreviousrelayState = fancurrentrelayState;
  fancurrentrelayState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (fancurrentrelayState != fanpreviousrelayState && fancurrentrelayState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    fanstartTime = millis();
    digitalWrite(fanrelay, LOW);//TURN IT ON
  }

  if (fancurrentTime - fanstartTime >= fanperiod) //ASK HOW LONG TO STAY ON
  digitalWrite(fanrelay, HIGH); //DEBOUNCE
  {
    Serial.println("Pump cycle complete");
    
    delay(50);
  }





}

i have updated the code. here is the part of the script causing issues,, it seems to turn on and then off right away without wait for the on time. how is fancurrenttime and fanstarttime = to fan period of 2000ms. it seems to ignore if (fancurrentTime - fanstartTime >= fanperiod) or im looking at it wrong. help!!! :slight_smile:

  //MIST CIRCULTION AFTER PUMP OFF //HAVING PROBLEMS\\\
  fancurrentTime = millis();
  fanpreviousrelayState = fancurrentrelayState;
  fancurrentrelayState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (fancurrentrelayState != fanpreviousrelayState && fancurrentrelayState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    fanstartTime = millis();
    digitalWrite(fanrelay, LOW);//TURN IT ON
  }

  if (fancurrentTime - fanstartTime >= fanperiod) //ASK HOW LONG TO STAY ON
  digitalWrite(fanrelay, HIGH); //DEBOUNCE
  {
    Serial.println("Pump cycle complete");
    
    delay(50);
  }

please help me!!

  if (fancurrentTime - fanstartTime >= fanperiod) //ASK HOW LONG TO STAY ON
  digitalWrite(fanrelay, HIGH); //DEBOUNCE
  {
    Serial.println("Pump cycle complete");
    
    delay(50);
  }

Once the condition in the if test is true what will stop it being true the next time the test is executed ?

actually to my relays HIGH is off and LOW is on. so that part that you just quoted is to turn it off.so we have this script

//MIST CIRCULTION AFTER PUMP OFF //HAVING PROBLEMS\\\
  fancurrentTime = millis();
  fanpreviousrelayState = fancurrentrelayState;
  fancurrentrelayState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (fancurrentrelayState != fanpreviousrelayState && fancurrentrelayState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    fanstartTime = millis();
    digitalWrite(fanrelay, LOW);//TURN IT ON
  }

  if (fancurrentTime - fanstartTime >= fanperiod) //ASK HOW LONG TO STAY ON
  digitalWrite(fanrelay, HIGH); //DEBOUNCE
  {
    Serial.println("Pump cycle complete");
    
    delay(50);
  }

this is supposed to run the fan for an amount of time after the pump shuts off. instead it comes on then off right away and "pump cycle complete" keeps blowing up my serial session. it keeps setting it HIGH. i have it working right now like this

   //mist CYCLE 
  mistcurrentTime = millis();
  previousmistbuttonState = currentmistbuttonState;
  currentmistbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  
  if (currentmistbuttonState != previousmistbuttonState && currentmistbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    miststartTime = millis();
    digitalWrite(mistbutton, LOW);//TURN IT ON
    delay(5000);
    digitalWrite(mistbutton, HIGH);
    

  }


}

but im not sure what other bugs are going to popup

i better give an updated copy of my sloppy script who's names correlate with mist.

//READ ONLY BUTTON CONFIGURATION
const int pumprelay = A1;
const int drainbutton = A1;
const int fanrelay = A0;
const int drainrelay = A4;
const int mistbutton = A0;

//INITAL PINSTATES
int fanlastState = HIGH;
int mistbuttonState = HIGH;
int draincounter = 0;
int pumpcounter = 0;
int fancounter = 0;
int drainrelayState = HIGH;
int fanrelayState = HIGH;
int pumprelayState = HIGH;
int drainbuttonState = HIGH;

//FAN ON/OFF CYCLE
unsigned long previousMillis = 0; //
unsigned long interval = 0; //
unsigned long onInterval = 240000UL; //  FAN ON TIME 5 MINUTES 240000UL
unsigned long offInterval = 1320000UL; // FAN OFF TIME 22 MINUTES 1320000UL

//PUMP ON/OFF CYCLE
unsigned long interval2 = 0;
unsigned long pumppreviousMillis = 0;
unsigned long pumponInterval = 36000UL; // spray on time 26 SECONDS 36000UL
unsigned long pumpoffInterval = 6480000UL; // sprayer off time 1.8 HRS 6480000UL

//DRAIN RELAY ON TIME
unsigned long startTime;
unsigned long currentTime;
unsigned long period = 2000; //DRAIN OPEN TIME
int previousdrainbuttonState = HIGH;
int currentdrainbuttonState = HIGH;

//CIRUATION CONTROLL AFTER PUMPOFF
unsigned long interval3 = 0;
unsigned long miststartTime;
unsigned long mistcurrentTime;
unsigned long mistperiod = 2000; //DRAIN OPEN TIME
int previousmistbuttonState = HIGH;
int currentmistbuttonState = HIGH;
void setup() {
interval = offInterval;
interval3 = mistperiod;
  interval2 = pumpoffInterval;
  pinMode (mistbutton, INPUT_PULLUP);
  pinMode (drainbutton, INPUT_PULLUP); //DRAIN ACTIVATION PIN
  pinMode (fanrelay, OUTPUT); //FAN POWER RELAY
  pinMode (pumprelay, OUTPUT); //WATER PRESSURE PUMP
  pinMode (drainrelay, OUTPUT); //DRAIN SOLENOID POWER RELAY
  digitalWrite(pumprelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(fanrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainrelay, HIGH); //SET INITAL RELAY STATE
  digitalWrite(drainbutton, HIGH);//SET INITAL BUTTON STATE
  digitalWrite(mistbutton, HIGH);
  Serial.begin(9600);
  Serial.print("Ready");
}

void loop() {

  unsigned long currentMillis = millis();

  //FAN CYCLE
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    if (fanrelayState == HIGH) { //IF ITS OFF
      fanrelayState = LOW; // THEN TURN ON

      interval = onInterval; // ASK HOW LONG TO STAY ON
      Serial.println ("fan relay on");
      fancounter = fancounter + 1;
      Serial.println(fancounter);
    }
    else {
      fanrelayState = HIGH; // OTHERWISE OFF
      interval = offInterval; //ASK HOW LONG TO STAY OFF
    }
    digitalWrite(fanrelay, fanrelayState); //UPDATE STATUS OF FAN
  }

  //PUMP CYCLE

  if (currentMillis - pumppreviousMillis > interval2) {
    pumppreviousMillis = currentMillis;
    if (pumprelayState == HIGH) { //IF ITS OFF

      pumprelayState = LOW; // TURN IT ON
      digitalWrite(fanrelay, LOW);
      interval2 = pumponInterval; //ASK HOW LONG TO TURN IT ON
      Serial.println ("pump relay on");
      pumpcounter = pumpcounter + 1;
      Serial.println(pumpcounter);

    }

    else {
      digitalWrite(fanrelay, HIGH);
      pumprelayState = HIGH; //OTHERWISE TURN IT OFF
      interval2 = pumpoffInterval; //ASK HOW LONG TO TURN IT OFF
    }

    digitalWrite(pumprelay, pumprelayState); //DEBOUNCE
    delay(50);


  }
  //DRAIN CYCLE
  currentTime = millis();
  previousdrainbuttonState = currentdrainbuttonState;
  currentdrainbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  if (currentdrainbuttonState != previousdrainbuttonState && currentdrainbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    startTime = millis();
    digitalWrite(drainrelay, LOW);//TURN IT ON
    Serial.println ("drain relay on");
    draincounter = draincounter + 1;
    Serial.println(draincounter);
  }

  if (currentTime - startTime >= period) //ASK HOW LONG TO STAY ON
  {
    digitalWrite(drainrelay, HIGH); //DEBOUNCE
    delay(50);
  }


    
   //mist CYCLE 
  mistcurrentTime = millis();
  previousmistbuttonState = currentmistbuttonState;
  currentmistbuttonState = digitalRead(pumprelay); //ASK STATE OF DRAIN BUTTON
  
  if (currentmistbuttonState != previousmistbuttonState && currentmistbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    miststartTime = millis();
    digitalWrite(mistbutton, LOW);//TURN IT ON
    delay(5000);
    digitalWrite(mistbutton, HIGH);
    

  }


}

Ive been looking at this basic example of an if statement.

if (pinFiveInput < 500)
{
// action A
}
else
{
// action B
}

when you look at my code. if i change

 if (currentmistbuttonState != previousmistbuttonState && currentmistbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    miststartTime = millis();
    digitalWrite(mistbutton, LOW);//TURN IT ON
    delay(5000);
    digitalWrite(mistbutton, HIGH);
    

  }

to

 if (currentmistbuttonState != previousmistbuttonState && currentmistbuttonState == HIGH)//ASK WHATS THE STATE OF THE BUTTON
  {
    miststartTime = millis();
    digitalWrite(mistbutton, LOW);//TURN IT ON

}
if (mistcurrentTime - miststartTime >= mistperiod) //ASK HOW LONG TO STAY ON
  digitalWrite(mistbutton, HIGH); //DEBOUNCE
  {
    Serial.println("Pump cycle complete");
    
    delay(50);
  }

then it continues to run part b of that if statement over and over again.