Tuesday, July 1, 2014

60: Water Sensor

I wanted an alarm on my basement sump. My AC and de-humidifier drain into the sump which is usually seeps away on its own. But then it might not. Anyway, I checked the web and found--

http://pi.gate.ac.uk/pages/basics.html#flood-alarm

I'm not much good at interpreting wiring diagrams, but my 2nd try worked. Here transcribed to Fritzing.

A couple of notes: the 2 resistors (L to R) are 1K and 100K (in case the wires are shorted). Also, my first try didn't sense water: I had only stripped about 1/4" of the 22 gauge wire and the space between was also about 1/4". So I stripped back to bare another 1/4" and taped the copper ends only 1mm apart. Then it worked. 
At first I tested with an actual glass of water
but a little spit on my finger worked as well.
Note: that copper has started to tarnish within a day. 
How long before corrosion connects the wires?

The programming can be done in Linux shell.

Setup:
   gpio -g mode 7 in  # BCM # 7 is my water sensing input

Test:
   gpio -g read 7     # "0" == dry, "1" == wet

And the "-g" option means that you are using BCM pin numbering.

Here's a way-too-simple shell program:
============================
Water=0

gpio -g mode 7 in  # BCM pin 7 is INPUT
if [ $? -ne 0 ]
then
    echo Cannot assign pin 7
exit 1
fi

while true
do
    Water=`gpio -g read 7`
    if [ $Water -eq 1 ]
    then
        sleep 5 # might be a false reading
        Water=`gpio -g read 7`
        if [ $Water -eq 1 ] # 2nd wet reading
        then
            echo "Send dated email and/or text msg!"
            sleep 3000 # sleep a long time / don't nag
        fi
    else
        sleep 300 # or some such
    fi
done

No comments:

Post a Comment