Aquarium controller with a debounce on the temperature sensor

When a wave makes the float go up and down, I do not want the pump to trigger. My aim is when the float is moved to the opposite state of normal, it must be there for a set amount of time before the relay is activated to turn the pump on.

What I have right now is a basically a timer which at the set interval, checks the state of the float. Sometimes that interval is just about up when the float is activated and it maybe .25 seconds before the pump activates this time, and it maybe 2.75 seconds before it activated that time rather then the full amount of the interval each time there is a state change.

Pseudo code:

if float == LOW

wait 3 seconds and the float is still LOW

digitalWrite float low

else keep float high

vs what I have

wait 3 seconds and check the float

if float == LOW

digitalWrite float low

else keep float high