/*******************************************************************
** This program will utilize a high and low level sensor system to *
** cycle a pump in order to maintain a specific volume range within*
** a vessel. The level sensors are comprised of a pair of wire ends*
** that will be shorted by the fluid to activate. The pump will be *
** operated by a relay. Version 1, 01/21/2014 by Mike Murphy *
*******************************************************************/
/*******************************************************************
* METHODS *
* checkHighLevel() *
* checkLowLevel() *
* pumpStatus() *
* *
* INPUTS *
* High Level Sensor -- Active = LOW (sensor shorted) *
* Low Level Sensor -- Active = HIGH (sensor open) *
* *
* OUTPUTS -- Active = HIGH *
* Pump (via relay) *
* Status LED(s) *
*******************************************************************/
/********************************************************************
* OPERATION *
* At initialization the pump will be set to off (LOW). The *
* checkHighLevel() method will determine whether fluid is in *
* contact with the high sensor leads. If the sensor is wet (logic *
* LOW), the pumpStatus is set HIGH, turning the pump ON. If *
* fluid is not in contact with the sensor the method will end *
* and the checkLowLevel() method will be called. If the low sensor *
* is wet (logic LOW), the pump continues to run. If the low sensor *
* is dry (logic HIGH), the pump is shut off by setting the *
* pumpStatus to off(LOW). A delay will be initiated then the loop *
* start over. *
********************************************************************/
const int HighSensor = 2; // High sensor assigned to pin 2
const int LowSensor = 3; // Low sensor assigned to pin 3
const int Pump = 4; // Pump assigned to pin 4
const int pumpLED = 5; // Pump status LED assigned to pin 5
// Pull-up resistors keep the sensors HIGH (Normally Open Configuration)
int highSensorState = 0; // status of high sensor (LOW is active)
int lowSensorState = 0; // status of low sensor (HIGH is active)
void setup()
{
Serial.begin(115200);
pinMode(HighSensor, INPUT);
pinMode(LowSensor, INPUT);
pinMode(Pump, OUTPUT);
pinMode(pumpLED, OUTPUT);
Serial.print("Pin modes set....");
digitalWrite(Pump, LOW); // Initialize pump OFF
digitalWrite(pumpLED, LOW); // pump status light OFF
}
void checkHighLevel()
{
highSensorState = digitalRead(HighSensor);
// if the sensor is wet, turn the pump on
if (highSensorState == LOW)
{
digitalWrite(Pump, HIGH);
digitalWrite(pumpLED, HIGH);
}
}
void checkLowLevel()
{
lowSensorState = digitalRead(LowSensor);
// if the sensor is dry, turn the pump off
if (lowSensorState == HIGH)
{
digitalWrite(Pump, LOW);
digitalWrite(pumpLED, LOW);
}
}
void loop()
{
checkHighLevel();
checkLowLevel();
delay(2000);
}