Thanks
Here Condition to start Motor is,if any tank level goes below Low Level .
Motor prime purpose is to Fill that Empty Tank but take this opportunity to refill others tanks if any tank level bellow High Level. ( It doesnt mean to start motor if level goes bellow High Level,again motor will start only when any tanl Low Level reaches)
Exactly
if you take these conditions
if any of the three sensors
highLevel1
highLevel2
highLevel3
reports water level is not at maximum
which means the water-level is a single inch below maximum
and sump-levelsensor reports "there is water to fill in"
and then switch on pump
the pump will switch on everytime the waterlevel of one tank is a single inch below maximum. And this means the pump will switch on pretty often and run for a short time because it takes just a short time to fill a single inch into the tank.
if you take the condition
one of the three low-level-sensors report "waterlevel is at lowest level"
this means the pump will have longer pauses because it takes longer to pour water out of the tank until lowest level is reached. Then pump switches on and pump will run for a longer time until the tank is filled up from lowest level to the maximum-level.
The logic can be programmed in a lot of ways.
Me personal I prefer a collection short conditions that set / reset a bolean flag-variable.
to make it easy to maintain code you should use self-explaining names for everything.
read through this code. I'm pretty sure that you will understand most of it because of the self-explaining names and the comments.
anyway if you have any questions just ask them
// // define SELF-explaining names for variables and constants
const byte triggered = LOW; // if triggered means IO-pin is high swap LOW and HIGH
const byte UNtriggered = HIGH;
const byte ON = HIGH; // if pump is switched on with LOW swap HIGH and LOW
const byte OFF = LOW;
const byte OPEN = HIGH; // if valve is opened with LOW swap HIGH and LOW
const byte CLOSED = LOW;
// INPUT PINS
const byte lowLevel1_Pin = 3;
const byte highLevel1_Pin = 4;
const byte sump_Pin = 5; // Sump Level
const byte lowLevel2_Pin = 6;
const byte highLevel2_Pin = 7;
const byte lowLevel3_Pin = 8;
const byte highLevel3_Pin = 9;
// OUTPUT PINS
const byte motor_Pin = 13;
const byte valve1_Pin = A0;
const byte valve2_Pin = A1;
const byte valve3_Pin = A2;
boolean PumpInWater = false;
void setup () {
// INPUTS
pinMode(lowLevel1_Pin, INPUT_PULLUP);
pinMode(highLevel1_Pin, INPUT_PULLUP);
pinMode(lowLevel2_Pin, INPUT_PULLUP);
pinMode(highLevel2_Pin, INPUT_PULLUP);
pinMode(lowLevel3_Pin, INPUT_PULLUP);
pinMode(highLevel3_Pin, INPUT_PULLUP);
pinMode(sump_Pin, INPUT_PULLUP);
// OUTPUTS
digitalWrite(motor_Pin,OFF); // initially switch off
digitalWrite(valve1_Pin,CLOSED); // initalially close valve
digitalWrite(valve2_Pin,CLOSED);
digitalWrite(valve3_Pin,CLOSED);
pinMode(motor_Pin, OUTPUT);
pinMode(valve1_Pin, OUTPUT);
pinMode(valve2_Pin, OUTPUT);
pinMode(valve3_Pin, OUTPUT);
delay(1000);
}
void CheckLowLevelSensors() {
// check if one of the tanks is at low level
if (digitalRead(lowLevel1_Pin) == triggered) {
PumpInWater = true;
}
if (digitalRead(lowLevel2_Pin) == triggered) {
PumpInWater = true;
}
if (digitalRead(lowLevel3_Pin) == triggered) {
PumpInWater = true;
}
}
void CheckHighLevelSensorSwitchValves() {
// check if there is a tank which is not completely filled
// if not completely filled open valve
if (digitalRead(highLevel1_Pin) == UNtriggered) {
digitalWrite(valve1_Pin, OPEN);
}
else {
digitalWrite(valve1_Pin, CLOSED);
}
if (digitalRead(highLevel2_Pin) == UNtriggered) {
digitalWrite(valve2_Pin, OPEN);
}
else {
digitalWrite(valve2_Pin, CLOSED);
}
if (digitalRead(highLevel3_Pin) == UNtriggered) {
digitalWrite(valve3_Pin, OPEN);
}
else {
digitalWrite(valve3_Pin, CLOSED);
}
}
void loop () {
PumpInWater = false; // reset to false before checking
// only in case the sump has enough water for pumping
if (digitalRead(sump_Pin) == triggered) {
CheckLowLevelSensors();
CheckHighLevelSensorSwitchValves();
} // end of condition "if (digitalRead(sump_Pin) == triggered)"
if (PumpInWater) {
digitalWrite(motor_Pin, ON);
}
else {
digitalWrite(motor_Pin, OFF);
}
}
best regards Stefan
Thank You Very Much Sir.... All Ok but following issues are observed:
- When Sump is Triggered,All Valve are suppossed to be Turned Off/Clsoe...which is not happening.
- Secondly when all three tanks High & Lows are triggered ie all three tanks are dry but Motor is not Running. Even any Tank reaches Low Level Motor is not getting started.
look inside the comments of my code
const byte triggered = LOW; // triggered means IO-pin is high swap LOW and HIGH
const byte UNtriggered = HIGH;
const byte ON = HIGH; // pump is switched on with LOW swap HIGH and LOW
const byte OFF = LOW;
const byte OPEN = HIGH; // if valve is opened with LOW swap HIGH and LOW
const byte CLOSED = LOW;
you have to clarify what
digitalRead(sump) = low means
and what
digitalRead(sump) = high means
is the meaning of sump low there is enough water
or does sump low mean no water to pump
You have to clarify what
digitalRead(Lowlevel) == LOW means
if digitalRead (lowLevel) is LOW does this mean water is below low-level or does it mean water is above low-level?
same thing for high-level
if digitalRead (HighLevel) is LOW does this mean tank is completely full or
does it mean tank is not (yet) completely full?
Same thing for the valvles
does
digitalWrite(valve1,HIGH) mean valvle is opened ?
or
does
digitalWrite(valve1,HIGH) mean valvle is closed?
you have to clarify this.
Any postings with words that are not precise will result in just re-posting these questions.
Hello dino_t
You might provide a timing diagram to show all cases and their transitions to see how we can help.
Thanks
you have to clarify what
digitalRead(sump) = low means = Water is available in Sump
and what
digitalRead(sump) = high means = Sump is empty
You have to clarify what
digitalRead(Lowlevel) == LOW means
if digitalRead (lowLevel) is LOW does this mean water is below low-level or does it mean water is above low-level?
= it mean water is above low-level
same thing for high-level
if digitalRead (HighLevel) is LOW does this mean tank is completely full or
does it mean tank is not (yet) completely full?
= this mean tank is completely full
Same thing for the valvles
does
digitalWrite(valve1,HIGH) mean valvle is opened ?
= valve is opened
So here is a code-version with more constants that say what they are
// // define SELF-explaining names for variables and constants
const byte triggered = LOW; // triggered means IO-pin is high swap LOW and HIGH
const byte UNtriggered = HIGH;
const byte ON = HIGH; // pump is switched on with LOW swap HIGH and LOW
const byte OFF = LOW;
const byte OPEN = HIGH; // if valve is opened with LOW swap HIGH and LOW
const byte CLOSED = LOW;
const byte WaterAvailable = LOW;
const byte tankCompletelyFilled = LOW;
const byte tankNotYetFullyFilled = HIGH;
const byte waterBelowLowLevel = HIGH;
// INPUT PINS
const byte lowLevel1_Pin = 3;
const byte highLevel1_Pin = 4;
const byte sump_Pin = 5; // Sump Level
const byte lowLevel2_Pin = 6;
const byte highLevel2_Pin = 7;
const byte lowLevel3_Pin = 8;
const byte highLevel3_Pin = 9;
// OUTPUT PINS
const byte motor_Pin = 13;
const byte valve1_Pin = A0;
const byte valve2_Pin = A1;
const byte valve3_Pin = A2;
boolean PumpInWater = false;
void setup () {
// INPUTS
pinMode(lowLevel1_Pin, INPUT_PULLUP);
pinMode(highLevel1_Pin, INPUT_PULLUP);
pinMode(lowLevel2_Pin, INPUT_PULLUP);
pinMode(highLevel2_Pin, INPUT_PULLUP);
pinMode(lowLevel3_Pin, INPUT_PULLUP);
pinMode(highLevel3_Pin, INPUT_PULLUP);
pinMode(sump_Pin, INPUT_PULLUP);
// OUTPUTS
digitalWrite(motor_Pin,OFF); // initially switch off
digitalWrite(valve1_Pin,CLOSED); // initalially close valve
digitalWrite(valve2_Pin,CLOSED);
digitalWrite(valve3_Pin,CLOSED);
pinMode(motor_Pin, OUTPUT);
pinMode(valve1_Pin, OUTPUT);
pinMode(valve2_Pin, OUTPUT);
pinMode(valve3_Pin, OUTPUT);
delay(1000);
}
void CheckLowLevelSensors() {
// check if one of the tanks is at low level
if (digitalRead(lowLevel1_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
if (digitalRead(lowLevel2_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
if (digitalRead(lowLevel3_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
}
void CheckHighLevelSensorSwitchValves() {
// check if there is a tank which is not completely filled
// if not completely filled open valve
if (digitalRead(highLevel1_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve1_Pin, OPEN);
}
else {
digitalWrite(valve1_Pin, CLOSED);
}
if (digitalRead(highLevel2_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve2_Pin, OPEN);
}
else {
digitalWrite(valve2_Pin, CLOSED);
}
if (digitalRead(highLevel3_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve3_Pin, OPEN);
}
else {
digitalWrite(valve3_Pin, CLOSED);
}
}
void loop () {
PumpInWater = false; // reset to false before checking
// only in case the sump has enough water for pumping
if (digitalRead(sump_Pin) == WaterAvailable) {
CheckLowLevelSensors();
CheckHighLevelSensorSwitchValves();
} // end of condition "if (digitalRead(sump_Pin) == triggered)"
if (PumpInWater) {
digitalWrite(motor_Pin, ON);
}
else {
digitalWrite(motor_Pin, OFF);
}
}
And this is a code-version that has a lot of debug-output to the serial monitor.
Same logic but serial output to analyse what is going on in the code
// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// Take it for granted at the moment scroll down to void setup
// start of macros dbg and dbgi
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
// usage: dbg("1:my fixed text",myVariable);
// myVariable can be any variable or expression that is defined in scope
#define dbgi(myFixedText, variableName,timeInterval) \
do { \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
} while (false);
// usage: dbgi("2:my fixed text",myVariable,1000);
// myVariable can be any variable or expression that is defined in scope
// third parameter is the time in milliseconds that must pass by until the next time a
// Serial.print is executed
// end of macros dbg and dbgi
// print only once when value has changed
#define dbgc(myFixedText, variableName) \
do { \
static long lastState; \
if ( lastState != variableName ){ \
Serial.print( F(#myFixedText " " #variableName" changed from ") ); \
Serial.print(lastState); \
Serial.print( F(" to ") ); \
Serial.println(variableName); \
lastState = variableName; \
} \
} while (false);
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *
// // define SELF-explaining names for variables and constants
const byte triggered = LOW; // triggered means IO-pin is high swap LOW and HIGH
const byte UNtriggered = HIGH;
const byte ON = HIGH; // pump is switched on with LOW swap HIGH and LOW
const byte OFF = LOW;
const byte OPEN = HIGH; // if valve is opened with LOW swap HIGH and LOW
const byte CLOSED = LOW;
const byte WaterAvailable = LOW;
const byte tankCompletelyFilled = LOW;
const byte tankNotYetFullyFilled = HIGH;
const byte waterBelowLowLevel = HIGH;
// INPUT PINS
const byte lowLevel1_Pin = 3;
const byte highLevel1_Pin = 4;
const byte sump_Pin = 5; // Sump Level
const byte lowLevel2_Pin = 6;
const byte highLevel2_Pin = 7;
const byte lowLevel3_Pin = 8;
const byte highLevel3_Pin = 9;
// OUTPUT PINS
const byte motor_Pin = 13;
const byte valve1_Pin = A0;
const byte valve2_Pin = A1;
const byte valve3_Pin = A2;
boolean PumpInWater = false;
void setup () {
// INPUTS
pinMode(lowLevel1_Pin, INPUT_PULLUP);
pinMode(highLevel1_Pin, INPUT_PULLUP);
pinMode(lowLevel2_Pin, INPUT_PULLUP);
pinMode(highLevel2_Pin, INPUT_PULLUP);
pinMode(lowLevel3_Pin, INPUT_PULLUP);
pinMode(highLevel3_Pin, INPUT_PULLUP);
pinMode(sump_Pin, INPUT_PULLUP);
// OUTPUTS
digitalWrite(motor_Pin,OFF); // initially switch off
digitalWrite(valve1_Pin,CLOSED); // initalially close valve
digitalWrite(valve2_Pin,CLOSED);
digitalWrite(valve3_Pin,CLOSED);
pinMode(motor_Pin, OUTPUT);
pinMode(valve1_Pin, OUTPUT);
pinMode(valve2_Pin, OUTPUT);
pinMode(valve3_Pin, OUTPUT);
delay(1000);
}
void CheckLowLevelSensors() {
dbgi("entering LowLevelSensors",PumpInWater,1000);
dbgi("LLS1",digitalRead(lowLevel1_Pin),1000);
// check if one of the tanks is at low level
if (digitalRead(lowLevel1_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
dbgi("LLS2",digitalRead(lowLevel2_Pin),1000);
if (digitalRead(lowLevel2_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
dbgi("LLS3",digitalRead(lowLevel3_Pin),1000);
if (digitalRead(lowLevel3_Pin) == waterBelowLowLevel) {
PumpInWater = true;
}
dbgi("leaving LowLevelSensors",PumpInWater,1000);
}
void CheckHighLevelSensorSwitchValves() {
// check if there is a tank which is not completely filled
// if not completely filled open valve
if (digitalRead(highLevel1_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve1_Pin, OPEN);
}
else {
digitalWrite(valve1_Pin, CLOSED);
}
dbgi("HL1",digitalRead(highLevel1_Pin),1000);
dbgi("V1",digitalRead(valve1_Pin),1000);
if (digitalRead(highLevel2_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve2_Pin, OPEN);
}
else {
digitalWrite(valve2_Pin, CLOSED);
}
dbgi("HL2",digitalRead(highLevel2_Pin),1000);
dbgi("V2",digitalRead(valve2_Pin),1000);
if (digitalRead(highLevel3_Pin) == tankNotYetFullyFilled) {
digitalWrite(valve3_Pin, OPEN);
}
else {
digitalWrite(valve3_Pin, CLOSED);
}
dbgi("HL3",digitalRead(highLevel3_Pin),1000);
dbgi("V3",digitalRead(valve3_Pin),1000);
}
void loop () {
PumpInWater = false; // reset to false before checking
dbgi("0:top of loop",PumpInWater,1000);
// only in case the sump has enough water for pumping
if (digitalRead(sump_Pin) == WaterAvailable) {
dbgi("1:",digitalRead(sump_Pin),1000);
dbgc("1:",PumpInWater);
CheckLowLevelSensors();
dbgc("2:",PumpInWater);
CheckHighLevelSensorSwitchValves();
} // end of condition "if (digitalRead(sump_Pin) == triggered)"
if (PumpInWater) {
digitalWrite(motor_Pin, ON);
dbgi("P1 ON",digitalRead(motor_Pin),1000);
}
else {
digitalWrite(motor_Pin, OFF);
dbgi("P1 OFF",digitalRead(motor_Pin),1000);
}
dbgi("99:bottom of loop",PumpInWater,1000);
}
best regards Stefan
Truely You spend your valuable time on people like me,Its really Great!!! Many Thanks & God Bless You.
![]()
I tried @StefanL38's industrial strength solution, just to see how it actually did the task.
I ran into a few issues, so I modified the code a bit.
Here you can play with it, fun:
three tank valve pump simulation
The slide faders are the liquid level in the tank. The section that reads the slide faders can be replaced by the commented section above it for the real digital sensor complement.
The slide switch indicates the availability of sump liquid.
I added a "state" variable pumpState, which is whether we are pumping or not.
// plain version
const byte ON = HIGH;
const byte OFF = LOW;
const byte OPEN = HIGH;
const byte CLOSED = LOW;
const byte WaterAvailable = LOW;
const byte tankFull = HIGH; // a HIGH reading of the upper sensor == tank is full
const byte tankEmpty = HIGH; // a HIGH reading of the lower sensor == tank is empty
const byte lowLevel1_Pin = 3;
const byte highLevel1_Pin = 4;
const byte sump_Pin = 5; // Sump Level
const byte lowLevel2_Pin = 6;
const byte highLevel2_Pin = 7;
const byte lowLevel3_Pin = 8;
const byte highLevel3_Pin = 9;
const byte motor_Pin = 12; // thirteen is unlucky.
const byte valve1_Pin = A0;
const byte valve2_Pin = 10;
const byte valve3_Pin = 11;
void setup() {
// INPUTS
pinMode(lowLevel1_Pin, INPUT_PULLUP);
pinMode(highLevel1_Pin, INPUT_PULLUP);
pinMode(lowLevel2_Pin, INPUT_PULLUP);
pinMode(highLevel2_Pin, INPUT_PULLUP);
pinMode(lowLevel3_Pin, INPUT_PULLUP);
pinMode(highLevel3_Pin, INPUT_PULLUP);
pinMode(sump_Pin, INPUT_PULLUP);
// OUTPUTS
digitalWrite(motor_Pin,OFF);
digitalWrite(valve1_Pin,CLOSED);
digitalWrite(valve2_Pin,CLOSED);
digitalWrite(valve3_Pin,CLOSED);
pinMode(motor_Pin, OUTPUT);
pinMode(valve1_Pin, OUTPUT);
pinMode(valve2_Pin, OUTPUT);
pinMode(valve3_Pin, OUTPUT);
// delay(1000); // why?
}
void loop() {
delay(125); // no need for speed here
static bool pumpState = OFF;
// static bool valveState = CLOSED;
/* real world section input
bool tank1Full = digitalRead(highLevel1_Pin);
bool tank2Full = digitalRead(highLevel2_Pin);
bool tank3Full = digitalRead(highLevel3_Pin);
bool tank1Empty = digitalRead(lowLevel1_Pin);
bool tank2Empty = digitalRead(lowLevel2_Pin);
bool tank3Empty = digitalRead(lowLevel3_Pin);
*/
/* simpulated input section */
analogRead(A1);
int tank1Level = analogRead(A1);
analogRead(A2);
int tank2Level = analogRead(A2);
analogRead(A3);
int tank3Level = analogRead(A3);
bool tank1Full = tank1Level > 923;
bool tank2Full = tank2Level > 923;
bool tank3Full = tank3Level > 923;
bool tank1Empty = tank1Level < 100;
bool tank2Empty = tank2Level < 100;
bool tank3Empty = tank3Level < 100;
/* end of simulated tank sensor input */
if (tank1Empty || tank2Empty || tank3Empty)
pumpState = ON;
if (tank1Full && tank2Full && tank3Full)
pumpState = OFF;
// only in case the sump has enough water for pumping
if (digitalRead(sump_Pin) != WaterAvailable) {
pumpState = OFF;
digitalWrite(valve1_Pin, CLOSED);
digitalWrite(valve2_Pin, CLOSED);
digitalWrite(valve3_Pin, CLOSED);
digitalWrite(motor_Pin, OFF);
return; // no water available, all done
}
// open the valse for tanks that are not already full
if ((pumpState == ON) && !tank1Full)
digitalWrite(valve1_Pin, OPEN);
else
digitalWrite(valve1_Pin, CLOSED);
if ((pumpState == ON) && !tank2Full)
digitalWrite(valve2_Pin, OPEN);
else
digitalWrite(valve2_Pin, CLOSED);
// alternate valve expression. terneray operator, nothing to be afraid of
digitalWrite(valve3_Pin, ((pumpState == ON) && !tank3Full) ? OPEN : CLOSED);
// and... that pump
digitalWrite(motor_Pin, pumpState);
}
You may discern the IPO pattern I mentioned. Tip o' the hat to @paulpaulson!
HTH
a7
Great Help Sir....Thanks for valuable time
![]()
The Umbrella Academy were unanimous in the feeling that there was an error in my demo #30.
They objected to a valve opening when as little as a teaspoon of liquid may have escaped.
Their version below uses three state variables, one per tank, and runs a hysteresis logic on them, with the addition wrinkly but desired behaviour of opening the other tank valves so they refill (once!) and then are left alone until another time when any tank goes empty.
Play with it here
traditional hysteresis plus...
Note that now if you wiggle a tank that was full tank, the valve remains closed.
Don't forget the sump sensor slide switch! I forgot and the whole thing wasn't working at all...
// home version
const byte ON = HIGH;
const byte OFF = LOW;
const byte OPEN = HIGH;
const byte CLOSED = LOW;
const byte WaterAvailable = LOW;
const byte tankFull = HIGH; // a HIGH reading of the upper sensor == tank is full
const byte tankEmpty = HIGH; // a HIGH reading of the lower sensor == tank is empty
const byte lowLevel1_Pin = 3;
const byte highLevel1_Pin = 4;
const byte sump_Pin = 5; // Sump Level
const byte lowLevel2_Pin = 6;
const byte highLevel2_Pin = 7;
const byte lowLevel3_Pin = 8;
const byte highLevel3_Pin = 9;
const byte motor_Pin = 12; // thirteen is unlucky.
const byte valve1_Pin = A0;
const byte valve2_Pin = 10;
const byte valve3_Pin = 11;
void setup() {
// INPUTS
pinMode(lowLevel1_Pin, INPUT_PULLUP);
pinMode(highLevel1_Pin, INPUT_PULLUP);
pinMode(lowLevel2_Pin, INPUT_PULLUP);
pinMode(highLevel2_Pin, INPUT_PULLUP);
pinMode(lowLevel3_Pin, INPUT_PULLUP);
pinMode(highLevel3_Pin, INPUT_PULLUP);
pinMode(sump_Pin, INPUT_PULLUP);
// OUTPUTS
digitalWrite(motor_Pin,OFF);
digitalWrite(valve1_Pin,CLOSED);
digitalWrite(valve2_Pin,CLOSED);
digitalWrite(valve3_Pin,CLOSED);
pinMode(motor_Pin, OUTPUT);
pinMode(valve1_Pin, OUTPUT);
pinMode(valve2_Pin, OUTPUT);
pinMode(valve3_Pin, OUTPUT);
// delay(1000); // why?
}
void loop() {
delay(125); // no need for speed here
// static bool pumpState = OFF;
// alternate state variables
static bool tank1Needs, tank2Needs, tank3Needs;
// static bool valveState = CLOSED;
/* real world section input
bool tank1Full = digitalRead(highLevel1_Pin);
bool tank2Full = digitalRead(highLevel2_Pin);
bool tank3Full = digitalRead(highLevel3_Pin);
bool tank1Empty = digitalRead(lowLevel1_Pin);
bool tank2Empty = digitalRead(lowLevel2_Pin);
bool tank3Empty = digitalRead(lowLevel3_Pin);
*/
/* simpulated input section */
analogRead(A1);
int tank1Level = analogRead(A1);
analogRead(A2);
int tank2Level = analogRead(A2);
analogRead(A3);
int tank3Level = analogRead(A3);
bool tank1Full = tank1Level > 923;
bool tank2Full = tank2Level > 923;
bool tank3Full = tank3Level > 923;
bool tank1Empty = tank1Level < 100;
bool tank2Empty = tank2Level < 100;
bool tank3Empty = tank3Level < 100;
/* end of simulated tank sensor input */
// basic hysteresis
if (tank1Empty) tank1Needs = true;
if (tank2Empty) tank2Needs = true;
if (tank3Empty) tank3Needs = true;
if (tank1Full) tank1Needs = false;
if (tank2Full) tank2Needs = false;
if (tank3Full) tank3Needs = false;
// might as well top off the other tanks
if (tank1Empty || tank2Empty || tank3Empty) {
if (!tank1Full) tank1Needs = true;
if (!tank2Full) tank2Needs = true;
if (!tank3Full) tank3Needs = true;
}
// only in case the sump has enough water for pumping
if (digitalRead(sump_Pin) != WaterAvailable) {
digitalWrite(valve1_Pin, CLOSED);
digitalWrite(valve2_Pin, CLOSED);
digitalWrite(valve3_Pin, CLOSED);
digitalWrite(motor_Pin, OFF);
return; // no water available, all done
}
digitalWrite(valve1_Pin, tank1Needs ? OPEN : CLOSED);
digitalWrite(valve2_Pin, tank2Needs ? OPEN : CLOSED);
digitalWrite(valve3_Pin, tank3Needs ? OPEN : CLOSED);
digitalWrite(motor_Pin, (tank1Needs || tank2Needs || tank3Needs) ? ON : OFF);
}
Pumps and valves and hysteresis and IPO and the ternary operator. Time for a nap.
a7
Many Thanks Sir!!!
![]()