Hello as I am new to the forum and coding, I hope I do this correctly. What I am trying to accomplish is I have two capacitive sensors as inputs to turn a relay on or off to allow a valve to fill a tank. The valve is spring loaded so once the relay is shut off the valve will close. One sensor will be set near bottom of tank and the other near the top. I'm also using a display so that anyone can see if the system is currently filling or considered full. Here is my current code. Thanks in advance!
#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() {
filling = digitalRead(lowlevelsensor);
full = digitalRead(filledlevelsensor);
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() {
lcd.setCursor(3,0);
lcd.print("Company Name Here");
//code for opening valve
if(filling == 0){
digitalWrite(fillvalve, HIGH);
lcd.setCursor(3,2);
lcd.print("System Filling");
}
//code for closing valve
if(full & filling == 1) {
digitalWrite(fillvalve, LOW);
lcd.setCursor(3,2);
lcd.print("System Full");
}
{
Serial.print(digitalRead(fillvalve));
delay(1000);
}
}
11 posts - 6 participants