Arduino with relay and on-off rocker switch Help!

alright I get this

what else does it need?

@JaGa, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

ok, sorry for that!

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

When the pump is OFF, the above code will execute resulting the the pump turning ON.
pump1_interval = pump1_ON_time; makes our target time 2 seconds.


When the pump1 is ON the code below is executed:

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

pump1_interval = pump1_OFF_time; this makes our target 5 seconds

ok, now ill try if I can apply this to the other pump

Good

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switchFlag           = !ENABLED;

const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 180000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 5000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);

  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;

} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switchFlag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


  {
    if (millis() - pump2Millis >= pump2_interval)
    {
      pump2Millis = millis();

      if (pump2State == PUMPoff)
      {
        digitalWrite(pump2Relay, PUMPon);

        pump2State = PUMPon;

        pump2_interval = pump2_ON_time;
      }

      else
      {
        digitalWrite(pump2Relay, PUMPoff);

        pump2State = PUMPoff;

        pump2_interval = pump2_OFF_time;
      }

    }
  }



  


} //END of loop()

//********************************************************************************
void checkSwitches()
{
  //*********************************************                    S W I T C H 1
  //userSwitch code
  byte currentState = digitalRead(SWITCH1);

  //**********************
  //was there a change in state ?
  if (lastSwitch1State != currentState)
  {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump1Relay, PUMPon);

      //allow manual switch bypass
      switchFlag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch1
      digitalWrite(pump1Relay, PUMPoff);

      pump1State = PUMPoff;

      //cancel manual switch bypass
      switchFlag = DISABLED;
    }

  } //END of userSwitch code

  //*********************************************                    o t h e r S w i t c h e s
  //next switch code
  //*********************************************

} //END of   checkSwitches()

now I'm struggling again with the second switch, but Ill try again :smile:

can't find the mistake?!

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switchFlag           = !ENABLED;

const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte SWITCH2           = 8;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte lastSwitch2State        = OPENED;
byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 180000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 5000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);

  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;

} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switchFlag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


  {
    if (millis() - pump2Millis >= pump2_interval)
    {
      pump2Millis = millis();

      if (pump2State == PUMPoff)
      {
        digitalWrite(pump2Relay, PUMPon);

        pump2State = PUMPon;

        pump2_interval = pump2_ON_time;
      }

      else
      {
        digitalWrite(pump2Relay, PUMPoff);

        pump2State = PUMPoff;

        pump2_interval = pump2_OFF_time;
      }

    }
  }



  


} //END of loop()

//********************************************************************************
void checkSwitches()
{
  //*********************************************                    S W I T C H 1
  //userSwitch code
  byte currentState = digitalRead(SWITCH1);


  //**********************
  //was there a change in state ?
  if (lastSwitch1State != currentState)
  {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump1Relay, PUMPon);

      //allow manual switch bypass
      switchFlag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch1
      digitalWrite(pump1Relay, PUMPoff);

      pump1State = PUMPoff;

      //cancel manual switch bypass
      switchFlag = DISABLED;
    }

  } //END of userSwitch code

  //*********************************************                    o t h e r S w i t c h e s
  //next switch code
  //*********************************************


{

  //*********************************************                    S W I T C H 2
  //userSwitch code
  byte currentState = digitalRead(SWITCH2);
{

  //**********************
  //was there a change in state ?
  if (lastSwitch2State != currentState)
  {
    //update to the new state
    lastSwitch2State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump2Relay, PUMPon);

      //allow manual switch bypass
      switchFlag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch2
      digitalWrite(pump2Relay, PUMPoff);

      pump2State = PUMPoff;

      //cancel manual switch bypass
      switchFlag = DISABLED;
    }
  

it doesn't show me a mistake, but something is still not right. The switch2 doesn't work

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switchFlag           = !ENABLED;

const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte SWITCH2           = 8;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte lastSwitch2State        = OPENED;

byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 180000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 5000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);

  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;

} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switchFlag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


  {
    if (millis() - pump2Millis >= pump2_interval)
    {
      pump2Millis = millis();

      if (pump2State == PUMPoff)
      {
        digitalWrite(pump2Relay, PUMPon);

        pump2State = PUMPon;

        pump2_interval = pump2_ON_time;
      }

      else
      {
        digitalWrite(pump2Relay, PUMPoff);

        pump2State = PUMPoff;

        pump2_interval = pump2_OFF_time;
      }

    }
  }



  


} //END of loop()

//********************************************************************************
void checkSwitches()
{
  //*********************************************                    S W I T C H 1
  //userSwitch code
  byte currentState = digitalRead(SWITCH1);

  //**********************
  //was there a change in state ?
  if (lastSwitch1State != currentState)


    //*********************************************                  S W I T C H 2
  //userSwitch code
  byte currentState = digitalRead(SWITCH2);

  //**********************
  //was there a change in state ?
  if (lastSwitch2State != currentState)


  
  {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump1Relay, PUMPon);

      //allow manual switch bypass
      switchFlag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch1
      digitalWrite(pump1Relay, PUMPoff);

      pump1State = PUMPoff;

      //cancel manual switch bypass
      switchFlag = DISABLED;
    }

  } //END of userSwitch code

  //*********************************************                    o t h e r S w i t c h e s

 
 {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump2Relay, PUMPon);

      //allow manual switch bypass
      switchFlag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch2
      digitalWrite(pump2Relay, PUMPoff);

      pump2State = PUMPoff;

      //cancel manual switch bypass
      switchFlag = DISABLED;
    }

  } //next switch code
  //*********************************************

} //END of   checkSwitches()

You will need two flags, one for each switch:

boolean switch1Flag = !ENABLED;
boolean switch2Flag = !ENABLED;

I don't know why but pump relay one acs now very strange, it goes on and off directly

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switch1Flag           = !ENABLED;
boolean switch2Flag           = !ENABLED;


const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte SWITCH2           = 8;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte lastSwitch2State        = OPENED;

byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 5000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 2000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);
    pinMode(SWITCH2, INPUT_PULLUP);


  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;
  pump2_interval = pump2_OFF_time;


} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch1Flag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


  {
    if (millis() - pump2Millis >= pump2_interval)
    {
      pump2Millis = millis();

      if (pump2State == PUMPoff)
      {
        digitalWrite(pump2Relay, PUMPon);

        pump2State = PUMPon;

        pump2_interval = pump2_ON_time;
      }

      else
      {
        digitalWrite(pump2Relay, PUMPoff);

        pump2State = PUMPoff;

        pump2_interval = pump2_OFF_time;
      }

    }
  }



  


} //END of loop()

//********************************************************************************
void checkSwitches()
{
  //*********************************************                    S W I T C H 1
  //userSwitch code
  byte currentState = digitalRead(SWITCH1);

  //**********************
  //was there a change in state ?
  if (lastSwitch1State != currentState)


    //*********************************************                  S W I T C H 2
  //userSwitch code
  byte currentState = digitalRead(SWITCH2);

  //**********************
  //was there a change in state ?
  if (lastSwitch2State != currentState)


  
  {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump1Relay, PUMPon);

      //allow manual switch bypass
      switch1Flag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch1
      digitalWrite(pump1Relay, PUMPoff);

      pump1State = PUMPoff;

      //cancel manual switch bypass
      switch1Flag = DISABLED;
    }

  } //END of userSwitch code

  //*********************************************                    o t h e r S w i t c h e s

 
 {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump2Relay, PUMPon);

      //allow manual switch bypass
      switch2Flag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch2
      digitalWrite(pump2Relay, PUMPoff);

      pump2State = PUMPoff;

      //cancel manual switch bypass
      switch2Flag = DISABLED;
    }

  } //next switch code
  //*********************************************

} //END of   checkSwitches()
  {
    if (millis() - pump2Millis >= pump2_interval)
    {
      pump2Millis = millis();

Should be:

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch2Flag == !ENABLED)
  {
    //***********************************                          p u m p 2   T I M E R
    //is it time to toggle the pump relay ?
    if (millis() - pump2Millis >= pump2_interval)
    {
      //restart the TIMER
      pump2Millis = millis();

like this?

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switch1Flag           = !ENABLED;
boolean switch2Flag           = !ENABLED;


const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte SWITCH2           = 8;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte lastSwitch2State        = OPENED;

byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 5000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 2000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);
    pinMode(SWITCH2, INPUT_PULLUP);


  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;
  pump2_interval = pump2_OFF_time;


} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch1Flag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


//*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch2Flag == !ENABLED)
  {
    //***********************************                          p u m p 2   T I M E R
    //is it time to toggle the pump relay ?
    if (millis() - pump2Millis >= pump2_interval)
    {
      //restart the TIMER
      pump2Millis = millis();

  


} //END of loop()

//********************************************************************************
void checkSwitches()
{
  //*********************************************                    S W I T C H 1
  //userSwitch code
  byte currentState = digitalRead(SWITCH1);

  //**********************
  //was there a change in state ?
  if (lastSwitch1State != currentState)


    //*********************************************                  S W I T C H 2
  //userSwitch code
  byte currentState = digitalRead(SWITCH2);

  //**********************
  //was there a change in state ?
  if (lastSwitch2State != currentState)


  
  {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump1Relay, PUMPon);

      //allow manual switch bypass
      switch1Flag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch1
      digitalWrite(pump1Relay, PUMPoff);

      pump1State = PUMPoff;

      //cancel manual switch bypass
      switch1Flag = DISABLED;
    }

  } //END of userSwitch code

  //*********************************************                    o t h e r S w i t c h e s

 
 {
    //update to the new state
    lastSwitch1State = currentState;

    //**********************                                         C L O S E D
    //is the switch closed ?
    if (currentState == CLOSED)
    {
      //
      digitalWrite(pump2Relay, PUMPon);

      //allow manual switch bypass
      switch2Flag = ENABLED;
    }

    //**********************                                         O P E N E D
    //is the switch closed ?
    if (currentState == OPENED)
    {
      //toggle switch2
      digitalWrite(pump2Relay, PUMPoff);

      pump2State = PUMPoff;

      //cancel manual switch bypass
      switch2Flag = DISABLED;
    }

  } //next switch code
  //*********************************************

} //END of   checkSwitches()

You cannot just copy and paste things in a helter skelter fashion.

You are not handling the switches properly.


Always format your code by pressing CTRL T

ok, I'll try again. thanks!!

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch2Flag == !ENABLED)
  {
    //***********************************                          p u m p 2   T I M E R
    //is it time to toggle the pump relay ?
    if (millis() - pump2Millis >= pump2_interval)
    {
      //restart the TIMER
      pump2Millis = millis();


// W H E R E   I S   T H E   R E S T   O F   T H E   C O D E

omg I lost track, its confusing

#define CLOSED                 LOW
#define OPENED                 HIGH

#define ENABLED                true
#define DISABLED               false

#define PUMPon                 LOW
#define PUMPoff                HIGH

// ------------------------------------------------------

boolean switch1Flag           = !ENABLED;
boolean switch2Flag           = !ENABLED;


const byte pump1Relay        = 2;
const byte pump2Relay        = 4;
const byte SWITCH1           = 7;
const byte SWITCH2           = 8;
const byte heartbeatLED      = 13;

byte lastSwitch1State        = OPENED;
byte lastSwitch2State        = OPENED;

byte pump1State              = PUMPoff;
byte pump2State              = PUMPoff;

unsigned long pump1Millis;
unsigned long pump2Millis;
unsigned long heartbeatMillis;
unsigned long switchMillis;
unsigned long time_1;
unsigned long time_2;

unsigned long pump1_interval;
unsigned long pump2_interval;


// PUMP 1
const unsigned long pump1_OFF_time = 5000;
const unsigned long pump1_ON_time  = 2000;

// PUMP 2
const unsigned long pump2_OFF_time = 5000; //Pump 2 Change for delay (1000 = 1 second)
const unsigned long pump2_ON_time  = 2000; //Pump 2 Change for pump running time (1000 = 1 second)



//***************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);
  pinMode(pump1Relay, OUTPUT);
  pinMode(pump2Relay, OUTPUT);

  pinMode(SWITCH1, INPUT_PULLUP);
  pinMode(SWITCH2, INPUT_PULLUP);


  digitalWrite(pump1Relay, PUMPoff);
  digitalWrite(pump2Relay, PUMPoff);

  pump1_interval = pump1_OFF_time;
  pump2_interval = pump2_OFF_time;


} //END of setup()

//***************************************************************
void loop()
{
  //*************************************                          h e a r t b e a t   T I M E R
  //to see if the sketch is blocking,
  //toggle the heartbeat LED every 500ms
  if (millis() - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*************************************                          c h e c k S w i t c h   T I M E R
  //is it time to read the switches ?
  if (millis() - switchMillis >= 50)
  {
    //restart the TIMER
    switchMillis = millis();

    checkSwitches();
  }

  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch1Flag == !ENABLED)
  {
    //is it time to toggle the pump relay ?
    if (millis() - pump1Millis >= pump1_interval)
    {
      //restart the TIMER
      pump1Millis = millis();

      //is pump1 now OFF ?
      if (pump1State == PUMPoff)
      {
        digitalWrite(pump1Relay, PUMPon);

        pump1State = PUMPon;

        pump1_interval = pump1_ON_time;
      }

      else
      {
        digitalWrite(pump1Relay, PUMPoff);

        pump1State = PUMPoff;

        pump1_interval = pump1_OFF_time;
      }

    }
  }


  //*************************************
  //if the switch is 'not enabled' we can proceed with autmatic operation
  if (switch2Flag == !ENABLED)
  {
    //***********************************                          p u m p 2   T I M E R
    //is it time to toggle the pump relay ?
    if (millis() - pump2Millis >= pump2_interval)
    {
      //restart the TIMER
      pump2Millis = millis();




    }
    //if the switch is 'not enabled' we can proceed with autmatic operation
    if (switch2Flag == !ENABLED)
    {
      //***********************************                          p u m p 1   T I M E R
      //is it time to toggle the pump relay ?
      if (millis() - pump1Millis >= pump1_interval)
      {
        //restart the TIMER
        pump1Millis = millis();




      }





      //END of loop()

      //********************************************************************************
      void checkSwitches()
      {
        //*********************************************                    S W I T C H 1
        //userSwitch code
        byte currentState = digitalRead(SWITCH1);

        //**********************
        //was there a change in state ?
        if (lastSwitch1State != currentState)


          //*********************************************                  S W I T C H 2
          //userSwitch code
          byte currentState = digitalRead(SWITCH2);

        //**********************
        //was there a change in state ?
        if (lastSwitch2State != currentState)



        {
          //update to the new state
          lastSwitch1State = currentState;

          //**********************                                         C L O S E D
          //is the switch closed ?
          if (currentState == CLOSED)
          {
            //
            digitalWrite(pump1Relay, PUMPon);

            //allow manual switch bypass
            switch1Flag = ENABLED;
          }

          //**********************                                         O P E N E D
          //is the switch closed ?
          if (currentState == OPENED)
          {
            //toggle switch1
            digitalWrite(pump1Relay, PUMPoff);

            pump1State = PUMPoff;

            //cancel manual switch bypass
            switch1Flag = DISABLED;
          }

        } //END of userSwitch code

        //*********************************************                    o t h e r S w i t c h e s


        {
          //update to the new state
          lastSwitch1State = currentState;

          //**********************                                         C L O S E D
          //is the switch closed ?
          if (currentState == CLOSED)
          {
            //
            digitalWrite(pump2Relay, PUMPon);

            //allow manual switch bypass
            switch2Flag = ENABLED;
          }

          //**********************                                         O P E N E D
          //is the switch closed ?
          if (currentState == OPENED)
          {
            //toggle switch2
            digitalWrite(pump2Relay, PUMPoff);

            pump2State = PUMPoff;

            //cancel manual switch bypass
            switch2Flag = DISABLED;
          }

        } //next switch code
        //*********************************************

      } //END of   checkSwitches()