What I am trying to do: I want create a system with arduino that does two basic things that revolve around a whole house filter that is bringing used as the first filter in the water filtration system in a house on well water. Most houses I know of have a sediment filter with a ball valve for flushing out sand, then a 10" whole house filter with a wound polypropylene filter. I want to have a LED light come on with the pressure drop on the whole house filter is greater than a threshold (a yellow LED, I will call it the "time to order filter light"). Then once a a greater threshold is reached between the difference in pre and post sensors, I want the yellow LED to turn off, and a red LED to come on. I could probably write the code to make this happen, although I threw a wrench at myself when I decided that the sediment filter needs to have a valve that opens to flush out sand once a set psi is seen at the pre-filter sensor. I was using delay() lines until I discovered that I should have been using millis(), and I essentially need the code to being checking multiple things at once, and not get "stuck" on a delay() code.
No this is not for work and no this is not for an assignment. It is just a pain point that my neighbors and I have here in SW Idaho with our crappy well water.
The code I was working before I realized that I needed to use millis() commands:
float preVoltage; //declaring pre-filter sensor voltage
float postVoltage; //declaring of post-filter sensor voltage
float prePsi; //declaring pre-filter sensor psi
float postPsi; //declaring post-filter sensor psi
int preSensorValue = A0; //assigning pre-filter sensor to A0
int postSensorValue = A1; //assigning pre-filter sensor to A1
int readPreSensorValue; //declaring voltage of pre-filter sensor
int readPostSensorValue; //declaring voltage of post-filter senor
int yellowLED = A2; //assigning pin number to yellow LED
int yellowLEDThresholdPsi = 5; //assigning a pressure threshold for yellow LED to illuminate
int redLED = A3; //assigning pin number to red LED
int redLEDThresholdPsi = 10; //assigning a pressure threshold for red LED to illuminate
int flushValveSolenoid = A6; //assigning pin number to flush valve
int flushValveThresholdPsi = 50; //assinging a pressure threshold for flush out valve to open
int flushValveDelay = 30000; //assigning a delay for flush out valve
void setup() {
Serial.begin(9600); //initialize serial communication at 9600 bits per second
pinMode(preSensorValue, INPUT); //sets pre-filter sensor value as input
pinMode(postSensorValue, INPUT); //sets post-filter sensor value as input
pinMode(yellowLED, OUTPUT); //sets yellow LED as output
pinMode(redLED, OUTPUT); //sets red LED as output
pinMode(flushValveSolenoid, OUTPUT); //sets flush valve solenoid as output
}
void loop() {
readPreSensorValue = analogRead(preSensorValue); //read raw voltage from pre-filter sensor
preVoltage = (5./1023.) * preSensorValue; //calculating voltage from pre-filter sensor
prePsi = (preVoltage - 0.5) * (100.0) / (4.5 - 0.5); //caculating psi from pre-filter sensor
Serial.println("Pre-filter sensor psi is currentlty: " prePsi); //print out pre-filter sensor psi
delay(2000); //delay in between reads for stability
readPostSensorValue = analogRead(postSensorValue); //read raw voltage from post-filter sensor
postVoltage = (5./1023.) * postSensorValue; //calculating voltage from post-filter sensor
postPsi = (postVoltage - 0.5) * (100.0) / (4.5 - 0.5); //caculating psi from post-filter sensor
Serial.Println("Post-filter sensor psi is currently: " postPsi); //print out post-filer sensor psi
if (prePsi < flushValveThreshold) { //if the psi is lower than treshold
digitalWrite(flushValveSolenoid, HIGH); //open flush out valve
delay(flushValveDelay); //delay for flush out valve
digitalWrite(flushValveSolenoid, LOW); //close flush out valve
}
if (postPsi - prePsi > yellowLEDThresholdPsi) { //if the pressure drop is greater than threshold
digitalWrite(yelowLED, HIGH); //turn on the yellow LED
}
}