//#include "Wire.h";
#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C lcd(0x27,20,4);
int water_low = 4;
int water_high = 5;
int pump_relay = 6;
int low_water_state = 0;
int high_water_state = 0;
int pump_run_time = 0;
bool pump_running = false;
void setup() {
//Serial.begin(9600);
lcd.init();
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("Poollevel controller");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print(" V0.9");
lcd.setCursor(0,3);
lcd.print(" Hello Rowen!");
pinMode(water_low,INPUT);
pinMode(water_high,INPUT);
pinMode(pump_relay, OUTPUT);
delay(1000);
}
void loop() {
low_water_state = digitalRead(water_low);
high_water_state = digitalRead(water_high);
//Serial.print(low_water_state);
//Serial.print(", ");
//Serial.println(high_water_state);
if((low_water_state == 0) && (high_water_state == 0)){
lcd.setCursor(0,1);
lcd.print("High level: OK ");
lcd.setCursor(0,2);
lcd.print("Low level : OK ");
lcd.setCursor(0,3);
lcd.print("Pump has run: ");
lcd.setCursor(15,3);
lcd.print(pump_run_time);
pump_running = false;
digitalWrite(pump_relay,LOW);
}
else if((low_water_state == 1) && (high_water_state == 0)){
lcd.setCursor(0,1);
lcd.print("High level: OK ");
lcd.setCursor(0,2);
lcd.print("Low level : Reached ");
if(pump_running == false){
digitalWrite(pump_relay,LOW);
}
else if(pump_running == true){
digitalWrite(pump_relay, HIGH);
}
lcd.setCursor(0,3);
lcd.print("Pump has run: ");
lcd.setCursor(15,3);
lcd.print(pump_run_time);
}
else if((low_water_state == 1) && (high_water_state == 1)){
lcd.setCursor(0,1);
lcd.print("High level: Reached ");
lcd.setCursor(0,2);
lcd.print("Low level : Reached ");
digitalWrite(pump_relay,HIGH);
if(pump_running == false){
pump_running = true;
pump_run_time ++;
}
lcd.setCursor(0,3);
lcd.print("Pump has run: ");
lcd.setCursor(15,3);
lcd.print(pump_run_time);
}
else if((low_water_state == 0) && (high_water_state == 1)){
lcd.setCursor(0,1);
lcd.print("High level: Ok ");
lcd.setCursor(0,2);
lcd.print("Low level : OK ");
digitalWrite(pump_relay,LOW);
}
}