Hello All,
Appreciate any help or links to articles that can educate me on how to set up a timer for multiple conditions within an IF condition.
Using an Arduino ESP32 Nano with 4 water flow switches that are switching GND to a digital input to confirm water is flowing. If all switches are closed I have the Nano output to a relay closing contacts for a separate latching circuit. I have an initial 5 second delay on startup to allow the pump to get things moving before checking the flow switches are closed. The separate latching circuit needs to be reset manually if any of the safeties are open, and in some cases a flow issue might resolve itself within a short period, of which I would like to give it that time to do so. In this 4 water flow safety circuit I would like to set a 1 or 2 second delay in that if any of the flow switches OPEN for less than the 1-2 sec period it won't de-energize the relay.
Here is what I have thus far:
int out1 = 10;
int in1 = 2;
int in2 = 3;
int in3 = 4;
int in4 = 5;
const int pauseTime = 5000; // 5 seconds pause
unsigned long startTime = 0; // Variable to store start time
void setup() {
// put your setup code here, to run once:
pinMode(out1, OUTPUT);
digitalWrite(out1, HIGH);
pinMode(in1, INPUT_PULLUP);
pinMode(in2, INPUT_PULLUP);
pinMode(in3, INPUT_PULLUP);
pinMode(in4, INPUT_PULLUP);
startTime = millis(); // Set start time when program begins
}
void loop() {
if (millis() > startTime + pauseTime) {
// put your main code here, to run repeatedly:
if( (digitalRead(in1) == LOW) && (digitalRead(in2) == LOW) && (digitalRead(in3) == LOW) && (digitalRead(in4) == LOW) ) {
digitalWrite(out1, HIGH);
}
else {
digitalWrite(out1,LOW);
}
}
}
Thank you in advance!
Best,
Mark