This works but I would like to have a timed failsafe...
If the FLOAT_PIN goes LOW for more than 3 seconds, it will turn SOLENOID_PIN to LOW.
I can't figure out how to incorporate it into my loop. I tried delay() and started playing with millis() but all I keep finding is LED blinking samples...
I'm not very good with C++ - still learning.
const int FLOAT_PIN = 8; // Pin connected to FLOAT switch
const int SOLENOID_PIN = A0; // SOLENOID pin - active-high
void setup() {
Serial.begin(9600);
// Since the other end of the FLOAT switch is connected to ground, we need
// to pull-up the FLOAT switch pin internally.
pinMode(FLOAT_PIN, INPUT_PULLUP);
pinMode(SOLENOID_PIN, OUTPUT);
}
void loop() {
int floatswitch = digitalRead(FLOAT_PIN); // Read the state of the float switch
if (floatswitch == HIGH) {
// If the pin reads high, water is OFF.
Serial.println("Switch closed");
digitalWrite(SOLENOID_PIN, HIGH); // Turn the SOLENOID on
} else {
digitalWrite(SOLENOID_PIN, LOW); // Turn the SOLENOID off
}
}
floatFlag....if floatSwitch == high and floatFlag == false(floatFlag = true;tim = currentTime;)......if floatSwitch == low(floatFlag == false).......if floatFlag == true and currentTime == tim +3 seconds(turn on valve)