Pump Controling

Hi!

im want to creating a pump control so need some help to do that.
my hardware : Arduno mega and a 4 relay board (Opto Switched (HIGH=off),(LOW=on))
Relay board link :https://potentiallabs.com/cart/image/cache/catalog/Arduino/4-channel%20relay%20Module-800x800.jpg

So im want to creating this setup:

if im push button 1 the relay 1 (PUMP1) is ON, if im unpressed the button 1 the relay 1 is OFF

Secound state:

if im push button 1 the relay 2 (PUMP2) is ON, if im unpressed the button 1 the relay 2 is OFF

so this is a state machine if im not wrong.

Third state:

if im push button 2 the relay 1- 2 (PUMP1 AND PUMP2) is ON, if upress button 2 relays is OFF
but need some delay after relay 1 (PUMP1) is on.

a last state:

if im push button 3 the relay 3 (ALARM) is ON if upress button 3 relay is OFF

this is want to working.

int PUMP1 = 2;
int PUMP2 = 3;
int ALARM = 4;

int SensorButton1 = 9;
int SensorButton2 = 8;
int SensorButton3 = 10;

int state  = 0;
int old  = 0;
int buttonState = 0;

void setup()
{
  pinMode(SensorButton1, INPUT_PULLUP);
  pinMode(SensorButton2, INPUT_PULLUP);
  pinMode(SensorButton3, INPUT_PULLUP);


  pinMode(PUMP1, OUTPUT);
  pinMode(PUMP2, OUTPUT);
  pinMode(ALARM, OUTPUT);

  digitalWrite(PUMP1, HIGH);
  digitalWrite(PUMP2, HIGH);
  digitalWrite(ALARM, HIGH);
}

void loop()
{
  ///////////////////////////////////////// STAGE 1
  buttonState = digitalRead(SensorButton1);
  if (buttonState == 1)
  {
    delay(800);
    buttonState = digitalRead(SensorButton1);
    if (buttonState == 0)
    {
      state = old + 1;
    }
  }
  else
  {
    delay(400);
  }

  switch (state)
  {
    case 1:
      if (digitalRead(SensorButton1) == LOW)
      {
        digitalWrite(PUMP1, LOW);
      }
      else if (digitalRead(SensorButton1) == HIGH)
      {
        digitalWrite(PUMP1, HIGH);
      }
      old = state;
      break;

    case 2:

      if (digitalRead(SensorButton1) == LOW)
      {
        digitalWrite(PUMP2, LOW);
      }
      else if (digitalRead(SensorButton1) == HIGH)
      {
        digitalWrite(PUMP2, HIGH);
      }
      old = 0;
      break;
  }
  ///////////////////////////////////////// STAGE 2
  if (digitalRead(SensorButton2) == LOW)
  {
    digitalWrite(PUMP1, LOW);
    digitalWrite(PUMP2, LOW);
  }
  else
  {
    digitalWrite(PUMP1, HIGH);
    digitalWrite(PUMP2, HIGH);
  }
  ///////////////////////////////////////// STAGE 3
  if (digitalRead(SensorButton3) == LOW)
  {
    digitalWrite(ALARM, LOW);
  }
  else
  {
    digitalWrite(ALARM, HIGH);
  }
}

any help would be good.

any help would be good.

Help with what? What actually happens when you run the code? How does what actually happens differ from what you want to happen?

groundFungus:
Help with what? What actually happens when you run the code? How does what actually happens differ from what you want to happen?

In the code "stage 1" not working only just "stage 2 and 3 "

In the code "stage 1" not working only just "stage 2 and 3 "

The code is "STAGE 1" IS working. That it does not do what you expect means that your expectations are wrong.

What does the code ACTUALLY do? How do you KNOW? How does that differ from what you expect/want?