/*
https://forum.arduino.cc/t/need-assistance-with-coding/1260828
*/
#include <Wire.h> // deals with I2C connections
#include <LiquidCrystal_I2C.h> // activates the LCD I2C library
// Define pins for Valves
const int fillvalve = 22;
// Define pins for sensors
const int lowlevelsensor = 50;
const int filledlevelsensor = 52;
const int overfilledlevelsensor = 48;
int filling = 0; //varialbe to store read value
int full = 0; //variable to store read value
// OBJECT CONFIGURATIONS
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(9600);
// LCD Initialization
lcd.backlight();
lcd.init();
lcd.clear();
// Set valves as OUTPUT, sensors as INPUTS
pinMode(fillvalve, OUTPUT);
pinMode(lowlevelsensor, INPUT);
pinMode(filledlevelsensor, INPUT);
digitalWrite(fillvalve, LOW); //Initialize valve closed
}
void loop() {
bool needFilling = digitalRead(lowlevelsensor);
full = digitalRead(filledlevelsensor);
lcd.setCursor(3, 0);
lcd.print("Company Name Here");
//code for opening valve
if (filling == 0 && needFilling == 0) {
filling = 1;
digitalWrite(fillvalve, HIGH);
lcd.setCursor(3, 2);
lcd.print("System Filling");
}
//code for closing valve
if (full && filling) {
filling = 0;
digitalWrite(fillvalve, LOW);
lcd.setCursor(3, 2);
lcd.print("System Full ");
}
{
Serial.print(digitalRead(fillvalve));
delay(1000);
}
}