Just want to add a delay that only waits to perform the digitalwrite...
Right now it works once, but then the solenoid will not turn off...
here is some video help...
Float is just a reed switch, maybe needs more resistance.
const int FLOAT_PIN = 8; // Pin connected to FLOAT switch (OPEN=FULL, CLOSED/CONTINUTITY = NEED WATER)
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);
digitalWrite(SOLENOID_PIN, LOW);
pinMode(SOLENOID_PIN, OUTPUT);
}
void loop() {
digitalWrite(SOLENOID_PIN, LOW); //sanity check, water is normally off
if (digitalRead(FLOAT_PIN == LOW)) // if it needs water
{
delay(10000); // delay BEFORE filling.
while(digitalRead(FLOAT_PIN == LOW)){ // Fill till sensor says full, then exit. Water turned off at sanity check.
digitalWrite(SOLENOID_PIN, HIGH);
} //end while
} //end if
} //end loop