Hello all,
I'm working on a project to pump out a bucket when it gets full. I have two float switches (reed switches), one at the top and one at the bottom (so I don't burn out the pump), and an IOT relay that my pump plugs into. So far I am struggling with the logic and thought this forum might be able to help. Sure I could use one float switch and a timer, but I have two switches and would like to use them.
Logic:
When the top float switch is triggered (HIGH, bucket full), the pump should run until the bottom switch is NOT triggered (LOW, Inch or so of water left in bucket).
Here is my current bit of code that doesn't quite get me to what I'm trying to do. It performs well until the top float switch is triggered then the pump starts running and never turns off when the bottom float switch goes LOW. The LED turns on every time the pump is on.
//Float Switch
const int pinTopFloatSwitch = 5; //Pin Reed
const int pinBtmFloatSwitch = 4;//Pin Reed
const int pinLed = 13; //Pin LED
int TFS = 0;
int BFS = 0;
// Relay
#define relaypower 7 //Define relay power signal
void setup()
{
pinMode(pinLed, OUTPUT); //set up LED
pinMode(pinTopFloatSwitch, INPUT);//setup top float switch
pinMode(pinBtmFloatSwitch, INPUT);//setup bottom float switch
pinMode(relaypower, OUTPUT);//setup relay trigger
Serial.begin(9600);//print to serial
}
void loop(){
TFS = digitalRead(pinTopFloatSwitch); //
BFS = digitalRead(pinBtmFloatSwitch); //
if (TFS == HIGH) {
do{
digitalWrite(relaypower, HIGH);
digitalWrite(pinLed, HIGH);
Serial.println("Pump is Running");
delay(500);
} while (BFS == HIGH);
}
if (TFS == LOW && BFS == LOW){
digitalWrite(relaypower, LOW);
digitalWrite(pinLed, LOW);
Serial.println("Both switches off, pump not running");
delay(500);
}
else {
digitalWrite(relaypower, LOW);
digitalWrite(pinLed, LOW);
Serial.println("else");
delay(500);
}
}
Other things I've tried:
- This thread was getting close but the last entry said "It's impossible."
- This tutorial also got close but now quite