Adding a simple timed failsafe

Tried to figure this out, having some trouble with the millis() not sure how to drop in to my current if else loop...

Test_Float works great, just need to have that time out or delay out - if the float valve is HIGH water turns on. Want there to be a time out if the float valve is chewed off my dog.

3 seconds should do it.

2 versions Test_Float works, tried to add the millis() in the *add failsafe version

This was saposed to be fun, now i'm losing sleep.

TEST_FLOAT.ino (807 Bytes)

TEST_FLOAT_Add_FAILSAFE.ino (1.54 KB)

int timer = 0;
int floatPin = 1 // Whatever pin float is on

void loop() { 

if (digitalRead(floatPin) == HIGH && timer < 3001) {

// Turn water on
timer++;

}
timer = 0;

}

Post your code in code snippets.

Edited your code download, should work now!

TEST_FLOAT_Add_FAILSAFE.ino (663 Bytes)

Thanks for the help, but not working...

you had the FLOAT_PIN LOW, needs to go high to turn on....

"if (digitalRead(FLOAT_PIN) == [b]HIGH[/b] && timer < 3001) {

But it works once then hangs with the digital out set to HIGH, never turns the solienod off, when closing the float or with the time out....

const int FLOAT_PIN = 8; // Pin connected to FLOAT switch
const int SOLENIOD_PIN = A0; // SOLENIOD 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(SOLENIOD_PIN, OUTPUT);
  
}

void loop() { 

int timer = 0;

if (digitalRead(FLOAT_PIN) == HIGH && timer < 3001) {

digitalWrite(SOLENIOD_PIN, HIGH);
timer++;
delay(1);
}

if (timer > 2999) {
  while (digitalRead(FLOAT_PIN) == LOW) {
    delay(1000);
  }
}

}

Also posted at:

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.