Todd Anderson

I make things for the web, mobile, desktop and land.

flood-pi: Flood detection on Raspberry Pi

2014 December 4th by todd anderson

A lot has happened over the course of the current year. Among the biggest changes, we left Boston for Vermont! We have begun to settle in here in the beatuiful Champlain Valley and, of course, my oldest is enrolled in hockey lessons - a sport i know very little about, but am excited to learn from him.

As is expected from a big move, we have found outselves in different surroundings and different living spaces. We are no longer 4 people cramped in a tiny 2-bedroom condo along the train line in Brighton, MA; we are now 4 people in a ranch house with noone above or below us to complain about taking off their loud shoes when the baby is sleeping.

While the extra space of a house is wonderful, it comes with additional maintenance and care over renting an apartment. For instance, we never had a basement in our previous apartments and never had to worry about flooding or failures in a sump pump. Now we do. And we have had a handful of instances when it has occurred. While it is true that we have and will continue to have qualified people locate the source of the problem, I thought - in the meantime - it would be a fun little project to setup something that could alert me to possible water starting to accumulate in the basement.

a flood!

And from that flood-pi was born!

flood-pi

flood-pi is an open source Python project meant to be run on a Raspberry Pi. The Github repo for flood-pi has some more technical details, but essential flood-pi detects a "flood" by reading an analog value from a circuit completed by water.

The basic premise is that two leads with copper plates at the end (originally nails in my prototype) are set level to the floor of the basement and spaced about a inch apart from each other. One lead is connected to the power while the other lead is connected between the first pin of the mcp3008 and the ground. As water comes between the leads (most likely from the start of a flood), the circuit is complete and a reading from 0 to 1024 is read through the ADC. Some low values may come in but should be considered not a "positive" detection. As well, some high values may come in which typically means that somehow the leads started touching each other and be considered not a "positive" detection, either. In correlation to the distance between the leads, there is a middleground of values that would be considered a "positive" detection.

When a "positive" detection occurs, flood-pi then sends out an email to alert me. Then I can take appropriate action.

There is no analog in on Raspberry Pi, but i have set up projects reading potentiometers using the mcp3008 as described here on adafruit, so I knew i could use that setup for this project.

project

Here's some pictures of the project:

The leads.

leads

Raspberry Pi, running Debian-Wheezy with the flood-pi program running as a daemon. Edimax WiFi adapter for the interweb-bings and email-ery.

pi

The mcp3008 on its own breakout. (i soldered it up all by myself!)

mcp3008

installation

Here's some pictures of its installation in the basement:

full install

module install

lead install

We, thankfully, haven't been able to get a true "positive" reading since its installation, but I have submersed the leads in water for a short time to ensure i was being sent emails :)

flood-pi-admin

I couldn't just stop at getting emails. I am empoyed as a software developer by trade, so I had to keep writing software.

I wanted to aggregate the readings from flood-pi and get an overview of its workings (or failure of workings if it may come to that). I don't know if there could be any patterns found from the data as to when the sump pump fails or whatnot, but more data can't hurt, can it?

As such, flood-pi-admin was born!

about flood-pi-admin

flood-pi-admin is a NodeJS-based server that provides a RESTful API for POSTing and accessing data being reported by flood-pi. There is more detailed information on the Github repo for the project, but it has endpoints for the flood-pi detector to post confiuguration and reading data as well as two main routes for accessing information about past and current conditions.

It's pretty bare-bones at the moment, but i plan to add new features as they are required (or requested).

charts

The landing page and /level?range=(day|week|year|all) provide chart data with the level readings:

chart data

The red band across the middle of the chart is the "positive" value range provided from the flood-pi and should be considered possible flood detection. As mentioned previously, lower values may come in but not high enough to be considered "positive"; additionally, high values may come in which may actually mean that the leads have somehow started touching each other rather than completing the circuit with water.

isitflooded

There is also a direct page at /isitflooded that will let you know if it is currently considered flooded or not:

current detection

It also reports last reporting time and whether or not it should alert you to the flood-pi no longer reporting information.

conclusion

I had a lot of fun taking a small idea of being notified the nextr time their is water in the basement and transferring it to an actual physical devices that can send out emails upon completion of a circuit. Plus, i got better at soldering - i know the ADC breakout is a small assembly, but it made me happy the way it turned out.

If you have occasional water in your basement and have an interest in Raspberry Pi, i hope you check out the flood-pi program and install it. And if you have yourself a VPS, feel free to also setup the flood-pi-admin on it to access level reading data.

Now, onto the next little pet project i have in mind :)

Cheers!