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?
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 ...
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.