Pond Latching Circuit

Evening Guys,

I have recently decided to add some automation to my pond control to reduce the size and amount of relays and switches I have.

I am trying to create a circuit where a float switch will go high and also a momentary push button is pressed and then the pump and uv lamp will latch on unless the button is pressed again or the float switch goes low.

I have managed to get some code to make both of these instances happen but I cannot work out how to get them on the same code.

Can anyone help with this please ?

Below I have included the two types of code for the two switches and the latching circuit, any help of getting these all into one format would be brilliant.

Button_circuit_pond.ino (1.9 KB)

latch.ino (2.44 KB)

in Button_circuit_pond.ino, you only turn the motor/lamp on if both the button AND float are HIGH, but immediately turn the motor/lamp of if they are both NOT HIGH.

i think you want to turn the motor/lamp off if the button is HIGH AND the float is LOW but your not testing for the condition.

i don't think there's any need to debounce these inputs, you could simply add a couple second delay to avoid turning the motor/lamp on/off

Hi Greg,

The condition I am after is if the float switch is high, I then want to press the start button and this to then latch the motor and uv lamp on. I only want this to go off if the float switch goes low or I then press the start/stop button again or alternatively a individual stop button.

I have a bottom drain in the pond so I need the pump to cut out if the water level starts to drop.

Cheers

Tom

Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

when is the else condition true in this code

   if ((buttonState1 == HIGH) && (buttonState2 == HIGH)) {
        // turn LED on:

    } else {   // ??  if the float switch goes low or I then press the start/stop button

Apologies I will upload the code like this when I get back on my computer.

Greg, if I remember correctly that else states that if the the float switch goes low then the pump and uv turn off. I cant see the code at the moment as I am not on my computer.

I just want the output for the motor and uv relays to stay to keep running unless I press the button for off or the float switch goes low.

Struggling to work out how to make this happen in the code for both switches

so how about

   if ((button == HIGH) && (floatSw == HIGH)) {
        // turn LED on:
        delay (ONE_SEC);

    } 
    else if ((button == HIGH) && (floatSw == LOW)) {
        // motor/led off
        delay (ONE_SEC);
    }

may need to see that button goes LOW between a change

Pseudo-code:

//  Init globally
bool is_stuff_on = false;

//  in your loop
if (float_is_low)
{
    turn_stuff_off();
    is_stuff_on = false;
}
//  Check if button has just transitioned from off to on.  You don't want to keep toggling 
//  while the button is pressed
else if (button_just_been_pressed())
{ 
   //  Toggle state
   is_stuff_on = !is_stuff_on;

   if (is_stuff_on)
   {
        turn_stuff_on();
   }
   else
   {
      turn_stuff_off();
   }
}

I was wondering, is there any way that the float switch can be incorporated into the latch code ?

To say the code will only run if the float switch is high ? Then the latch/debounce code will then run ?

Or would it be easier to incorporate the debounce into the the first code ?

I'm new to arduino and ide so I'm just trying to get my head around how it works and how to get to all work together so a y help you guys give is much appreciated

   if ((button == HIGH) && (floatSw == HIGH)) {
        // turn LED on:
        delay (ONE_SEC);

    }
    else if (floatSw == LOW) {
        // motor/led off
        delay (ONE_SEC);
    }