Monitoring Input


I am trying to build a water top off system for my fish tank (i.e when water low activate the pump). So I got a simple "if" "else" statements to turn on the pump when water is low. I got the a digital input to monitor the water.

Lets say I run out the water inside the reservoir, I wouldn't want the pump to turn on for a long period of time. Is there a way I can monitor the Input state, say if input "HIGH" for 20 seconds, shut off the pump?

Any feedbacks would be appreciated :-)

Why not just put a water level sensor in the reservoir so it will not pump when it is out of water?

A temperature sensor on the pump might be easier than a water level sensor. Most pumps are cooled by the water they're pumping so an empty reservoir would mean that your pump would get hotter.

Water level sensor could be a simple float that trips a simple switch tied to an input, temperature independent. As it drops, pulls a slip of paper with it to uncover and optoisolator, LDR, phototransistor, etc. Or a mechanical low force switch. Or ...

Well I don't want to add another sensor, hope there is a way I can do with's possible?

note the time when you start the pump loop until your input changes OR 20 seconds elapses

Also, make sure you have a substantial time elapsed (an hour?) between checking the level, otherwise, when you're out of water in the reservoir and the tank needs water, the pump will repeatedly be turned on for 20 second stints. This will also limit the flooding you'll get if your tank level sensor malfunctions.