Advertisement

Sunday, January 12, 2014

Adjusted Detection Function in HESA

I have gotten a couple of false positives on the water detection circuit on my Home Environmental Sensor Array.  It happens about once a week for no reason.  Its not because the sump pump is running and splashing water up to the plug.

Rather than scientifically figure out what is happening, I adjusted the detection function.  It now has to detect water for 500 milliseconds (5 seconds) during the detection cycle.  The milliseconds do not have to be consecutive but the count resets in each new cycle.  A detection cycle lasts 1000 milliseconds (10 seconds).  So, water has to be detected for half of the detection cycle.

That should stop false positives.  The downside is that 3v of electricity will be in the water for at least five seconds until the program shuts off the power.

Here is the code for the detection circuit.

    # Look for input for up to 10 seconds
    # Water must be detected for five seconds for this function to return a positive result
    if hesaDebug: print ("Looking for a signal on pin " + str(pinIn))
    circuitTimer = 0 # Tracks how long the program looks for a signal
    highCount = 0    # Tracks positive results
    while (circuitTimer < 1000): # 100 = 1 second
        if GPIO.input(pinIn) == GPIO.HIGH:
            highCount += 1
            if hesaDebug: print ("Signal found.  highCount = " + str(highCount))
            if highCount > 500: 
retResult = 1
circuitTimer = 1000

        else:
            circuitTimer += 1

        time.sleep(0.01) # 10 milliseconds

We tested the code by putting the test leads into a cup of water from the faucet.  As long as it was in the water, the highCount increased.  If we pulled the leads out of the water before five seconds elapsed, the HESA did not report water.  It did detect water if left in the cup for five seconds.