programming logic needed for water level controller

i need programing logic for water level controller project, i am having two sensors one is high(H) and another one is low(L) both of these are placed in the tank in high and low positions they both produce logic 1 output if water touches the sensor else logic 0.

case1 let us assume that water is below low level that is both the sensors are in logic 0 now a relay must get on

case2 let us assume that water touches Low level so low level sensor is active and produce logic 1 and still the relay must be in on position

case3 now let us assume that water touches both high and low level sensors so both produce logic 1 output now the relay must be in OFF position

case4 now again the relay must get on only when both the sensors are in logic 0 state that is water is below LOW LEVEL AND VICE VERSA

H=0 L=0 RELAY 0N

L=1 H=0 RELAY ON

H=1 L=1 RELAY OFF

H=0 L=1 RELAY OFF

H=0 L=0 RELAY ON

L=1 H=0 RELAY ON

H=1 L=1 RELAY OFF

H=0 L=1 RELAY OFF

H=0 L=0 RELAY 0N

AND VICE VERSO

I think this will work easily if you also have a variable to record whether the pump is running.

  1. If the low sensor is 0 and the pump is off turn it on

  2. If the high sensor is 1 and the pump is on turn it off.

…R

As Robin implies in his answer you don’t need to check the combinations of the 2 sensor states.

start of loop
  if low sensor value is 0
    turn on the pump
    remember that the pump is running
  end of if
  else if high sensor is 1 and the pump is running
    turn off the pump
    remember that the pump is off
  end of else
end of loop

Simple state machine