Hi Guys n Gals,
Last year I designed and built a Brewery Controller, the brewery uses an Under Back* to automate this process I was using an sonar sensor to detect the level of ale and turn a pump on and off. Due to the amount of bubbles on the surface the readings were unreliable (some days would work fine other days would pack in) and the head brewer has been doing this process manually since.
Under Back
liquid flows in from the top, when the level reaches the top a pump is turned on, once the level reaches the bottom the pump is turned off.
I'm now going with a more simple approach of using two stainless steel float switches.
Logic as the Under back fills up ...
Bottom float switch HIGH > Pump LOW > Top float switch HIGH > Pump HIGH > Top float switch LOW > Pump HIGH > Bottom float switch LOW > Pump LOW.
I've designed a very basic circuit using two mini push buttons with pull-up resistors and an LED.
The code below works as expected but I wanted to know if there was a better way of doing it? (I'm no coder!!!!!!)
int pump = 12; // Pump relay is connected to pin 12
int highLevel = 11; // High level float switch is connected to pin 11
int lowLevel = 10; // Low level float switch is connected to pin 10
int valHigh; // Variable for reading highLevel pin status
int valLow; // Variable for reading lowLevel pin status
void setup() {
pinMode(pump, OUTPUT); // Set the Pump pin as output
pinMode(highLevel, INPUT); // Set the High level float switch pin as input
pinMode(lowLevel, INPUT); // Set the Low level float switch pin as input
}
void loop(){
valLow = digitalRead(lowLevel); // Read Low level float switch input value and store it in valLow
if (valLow != LOW) { // Check if the Low level float switch is floating
valHigh = digitalRead(highLevel); // Read High level float switch input value and store it in valHigh
if (valHigh != LOW) { // Check if the High level float switch is floating
digitalWrite(pump, LOW); // Turn Pump off
}
}
valLow = digitalRead(lowLevel); // Read Low level float switch input value and store it in valLow
if (valLow != HIGH) { // Check if the Low level float switch is floating
valHigh = digitalRead(highLevel); // Read High level float switch input value and store it in valHigh
if (valHigh != HIGH) { // Check if the High level float switch is floating
digitalWrite(pump, HIGH); // Turn Pump on
}
}
}
Thanks for looking,
Ryan