Facing challenges in Level Controller

Hello to all,

here Ivebeen trying to control 3 different capacity tanks.Initilally code was working perfectly when applied for only one tank.Now I have tried to extend same code for 3 tanks.
following logic want to introduced in code:

Note: First of All system makes sure Sump water is available then following steps to impliment:

  1. If any 0f tank Low Level reaches that time all 3 valves should Open/On and Motor start to fill liquid.
  2. if any tank level reaches High level then dedicated tank valve should be closed/off & motor keeps running.
  3. When all 3 tanks High Level reaches then all 3 valves should be closed/off & motor should be Turned Off simuntaneously.

I am new to Arduino, I would really appreciate if any guidance can be provided that how I can implement the project.

Thank you

Following code is used:

> // CONSTANTS
> 
> // INPUT PINS
> #define lowLevel1  3         
> #define highLevel1  4        
> 
> #define sump  5             // Sump Level
> 
> #define lowLevel2  6         
> #define highLevel2  7        
> 
> #define lowLevel3  8         
> #define highLevel3  9        
> 
> // OUTPUT PINS
> 
> #define motor 13            
> #define valve1  A0 
> #define valve2  A1 
> #define valve3  A2 
> 
> // variables
> int state = 0;
> int sumpLevel = 0;    // for sump
> int level = 0;        
> int lastlevel = 0;
> 
> void setup (){
>  
>  // INPUTS
>  pinMode(lowLevel1,INPUT_PULLUP);  
>  pinMode(highLevel1,INPUT_PULLUP); 
>  pinMode(lowLevel2,INPUT_PULLUP);  
>  pinMode(highLevel2,INPUT_PULLUP); 
>  pinMode(lowLevel3,INPUT_PULLUP);  
>  pinMode(highLevel3,INPUT_PULLUP);
>    
>  pinMode(sump,INPUT_PULLUP);  
>  
>   // OUTPUTS
>  pinMode(motor, OUTPUT);
>  pinMode(valve1, OUTPUT);
>  pinMode(valve2, OUTPUT);
>  pinMode(valve3, OUTPUT);
>  
>  delay(1000);
> 
>  startstoppump();
> }
> 
> //FUNCTION THAT CONTROL THE START AND STOP OF THE PUMP
> 
> void startstoppump(){ 
>  if(level == 20){
>     digitalWrite(valve1, HIGH);
>     digitalWrite(valve2, HIGH);
>     digitalWrite(valve3, HIGH);
>     digitalWrite(motor, HIGH);
>  }
>  else if (level =30){
>     digitalWrite(valve1, LOW);
>   }
>  else if (level =40){
>     digitalWrite(valve2, LOW); 
>   }
>  else if (level =50){
>     digitalWrite(valve3, LOW);
>   }
>  else if(level = 60){
>   digitalWrite(motor, LOW);
>  }
>  else if (level=70){
>     digitalWrite(valve1, LOW);  //LOW
>     digitalWrite(valve2, LOW);  //LOW
>     digitalWrite(valve3, LOW);  //LOW
>     digitalWrite(motor, LOW);   //LOW
>  }
> }
> 
> }
> 
> // MAIN LOOP
> void loop (){
>  // CHECK WATER LEVEL
>     if(digitalRead(lowLevel1)==HIGH || digitalRead(lowLevel2)==HIGH || digitalRead(lowLevel3)==HIGH /*&& (digitalRead(highLevel1)==HIGH || digitalRead(highLevel2)==HIGH || digitalRead(highLevel3)==HIGH) */&& digitalRead(sump)==LOW) level = 20;
>      if (digitalRead(highLevel2)==LOW && digitalRead(lowLevel2)==LOW && digitalRead(sump)==LOW)level = 40;
>      if (digitalRead(highLevel3)==LOW && digitalRead(lowLevel3)==LOW && digitalRead(sump)==LOW)level = 50;
>      if (digitalRead(highLevel1)==LOW && digitalRead(highLevel2)==LOW && digitalRead(highLevel3)==LOW && digitalRead(sump)==LOW)level = 60; //??? Doubtful
>      if (digitalRead(sump)==HIGH)level=70;
>     
>  //END OF CHECK WATER LEVEL
>  
>      if (level != lastlevel){
> 
>      startstoppump();
>     }
>  
> }

else if (level =30){

Is not the same as

else if (level == 30){

:wink:

1 Like

Also, did you mean

if(level <= 20){

Sir,

Please Have a look again on Code as Wrong code was posted by mistake & guide me please

Sir I will do it

You have:


else if (level =30){
 digitalWrite(valve1, LOW);

You need:


  else if (level == 30){
     digitalWrite(valve1, LOW);

Or maybe:


  else if (level <= 30){
    digitalWrite(valve1, LOW);

1 Like

Thanks for valuable time ,I will correct code accordingly

1 Like

Maybe you shouldn't open a valve if the corresponding tank is already at or above High level.

a7

Infact my moto is if motor is running that time again fill tanks to their High Level and High Level will close those valves again...

When a tank is full, and another gets low, you turn on the motor and open all the valves.

Immediately the you will close the valve(s) on the tank(s) that were already full. That did not trigger the motor.

Your tanks, valves and motors, so OK, I don't care. It just seems stupid. Also, I wonder how much over High level you are willing to let an already full tank get, bit by bit, as its valve is briefly opened a few times because another tank needs filling.

a7

May be I am wrong ,intension is to not to wait till low level reaches,if motor is running for others tank why not utilise this opporunity to refill tank to its High level so that water will available all time.

Oh, sorry. I was talking about when the other tanks are already at or above High.

Use the IPO model.

input - what are the tanks reading?

process - decide if the motor should be on or off and whether valves should be open(ed) or closed.

output - set the correct motor and valve control lines

Rinse and repeat.

Code writes itself.

a7

2 Likes

Thanks

If I understand right you want to fill up the tanks anytime a tank is below maximum.
Then this logic is enough

if any of the three sensors
highLevel1
highLevel2
highLevel3
reports water level is not at maximum
and sump-levelsensor reports "there is water to fill in"

then ==> switch on pump

if highLevel1 indicates tank is completely full close valve1
if highLevel2 indicates tank is completely full close valve2
if highLevel3 indicates tank is completely full close valve3

if all three sensors
highLevel1
highLevel2
highLevel3
report "tank is full"
switch off pump.

if sump-sensor reports "no water to pump" switch off pump

You have created some kind of code that seems to be really complicated and hard to maintain
because almost everything is hidden behind numbers.

What is the purpose of the low-level sensors?

based on my description above you don't need them.

If the pump shall only start if one of the three low-level-sensors reports
"tank at lowest level"
you could use a boolean flag to switch on the pump only if this flag-variable is set to true

best regards Stefan

Read (or reread) post #1, see requirement/desire 1 on the list.

It is the condition that any tank level goes below some lower limit that turns on the pump.

a7

Hard to know what would make a good algorithm without knowing what the tanks are used for. Is there likely to be a lack of water from the sump?

Sump capacity is more than enought,in worst case if Sump gets empty,as per given condition all valve & Motor will be turned off

Thanks for your time,exactly this is my project requirement.Switch off Pump as well as all valves.

As far as Low Level concern,it will work as normal case.Like if Anytank water level goes bellow Low Level.All Valve will be Opened & Motor will start filling water into all tanks.

Reasonbeing my project require Minimum switching opearation of motor.Let me clarify further.
Suppose we have 3 tanks

a) Tank1 is at Full Level (and motor is running to fill other tanks,No chance to open Tank1 Valve1 as HIGH Level Condition)

b) Tank2 level is bellow Full Level & above Low Level (and motor is running to fill tank1 as Tank2 is at Full Level,Grab this opportunity to Re-fill tank 2 to again its High Level by just opening its Valve2)

c) Whenever all 3 High Level touched,All valve & motor will be turned off.

d) repeat Cycle, if any Tank gets Low Level again then all 3 Valve should Open & motor to start filiing dedicated tank & Re-filling other Tanks if needs to be.

Exactly

True,but I stuck how to make correct logic