Aquaponics project

Hi there,

I've been trying with some aquaponics for a while now with pumps on timers and for the most part its been ok. The issue with pumps and timers is occasionally outside factors intervene and you end up either flooding a plant bed for too long or emptying a tank when timers fail. I've learnt a few things along the way like positioning pump feeds at a high level and making sure the tanks don't promote a siphon effect but I think I can make it better with some intelligence. I've been tinkering with various bits and pieces like water level sensors but I've settled on some WS-03 water level sensors to detect a low and high level and then a relay board to operate the pumps. I've bee struggling with some code and I'm at a very basic start.

At present the output only sends No low level and looped to the monitor. I'm probably being a real noob here but any guidance on what I'm doing wrong would be most appreciated. What I want to do is activate one relay when the low level sensor is 0 and then activates the other pump when the high level sensor it 1. Its to fill and empty a water tank of a time schedule to water plants. Thanks for reading.

int relayPin1 = 38;
int relayPin2 = 39;

void setup() {
  //start serial connection
  Serial.begin(9600);
  pinMode(51, INPUT_PULLUP);
  pinMode(53, INPUT_PULLUP);
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);
  digitalWrite(relayPin1, HIGH);
  digitalWrite(relayPin2, HIGH);
}

void loop() {
  int sensorValp1 = digitalRead(51);
  int sensorValp2 = digitalRead(53);
  Serial.print("Sensor 1:");Serial.println(sensorValp1);
  Serial.print("Sensor 2:");Serial.println(sensorValp2);
  delay(1000);

    if (sensorValp1 = 0) {
      Serial.println("Top level");
    }
    
    else if (sensorValp2 = 0){
      Serial.println("Lower level");
    }
    else if (sensorValp2 = 1){
      Serial.println("No low level");
    }
    else if (sensorValp1 = 1){
      Serial.println("No high level");
    }
    Serial.println("Looped");
}

Common error, this:

  if (sensorValp1 = 0)

should be:

  if (sensorValp1 == 0)

You could probably do this without needing the Arduino , just getting the level switches to operate the pumps.

Wow, my bad, thanks for the correction. Yeah I could do this without Arduino but long term I would like to build in other automation and will hopefully get some time to push this further. Pallet project on the way...

When the low level sensor is 0, does that mean the water level is LOWER than the sensor or HIGHER? How about the high level?