David Watson

Rain Barrel (2010)

Rain barrels installed

Overview

We've had a couple of rain barrels for several years. At our old house they were mainly used as a source of water for our garden. At the new house, we have much more of a problem with puddles around the house, so the rain barrels are an important buffer for managing the water from large storms. So rather than keeping the rain barrels full all the time, we now want to make sure the barrels are empty before a big rain. This obviously calls for some type of automation system! Something that can track the amount of water in the barrels as well as impending rain. Ideally the system will include a computer controlled valve to automatically drain the water into the garden either when the garden needs the water or before it rains.

Measuring the water level

I had found several ideas for tracking water level, but I wasn't really happy with any of them until I ran across a post at Spiff's Electronics Notebook about the Freescale MPX pressure sensors. The nice thing about using pressure sensors is that all the electronics can be located outside the water and the sensor provides a lot of resolution. Not that a lot of resolution is actually needed in this situation, but it should be useful in translating rainfall measurements into volume in the barrels.

Basic theory

Using a pressure sensor to measure the water level is basically the same as building a barometer. The pressor sensor is connected to a tube that extends down into the water. As the water level increases, the pressure in the tube will increase.

Hardware

Pressure sensors

Since we have two barrels, I needed two pressure sensors. The first one I bought was the MPX5010DP. This is a 5V differential pressure sensor, with through hole pins. I mistakenly thought I needed a differential sensor because I wanted to measure the pressure of the water relative to atmospheric pressure. It turns out that a gauge sensor is really what I wanted. It measures a pressure relative to atmospheric pressure. An absolute sensor measures pressure independent of atmospheric, which is what I was really trying to avoid. The second sensor I bought was the MPX5010GP, which is a gauge sensor.

The electronics are relatively simple. I used an Arduino for the microcontroller, and an XBee for the communications link. There's a small amount of hardware filtering, based on the datasheet for the MPX. The sensor outputs are then connected to an analog input pin on the Arduino. There are a few more connections, mainly to try to reduce the power draw so I can run the sensors for an entire summer on one set of batteries. Basically, the sensors are powered from digital output pins on the Arduino, and another digital output pin is connected to the XBee to put it to sleep between sensor readings.

Pressure tubing

Tubing connection to barrel

I tried to make the tubing running into the rain barrel neat and orderly. I also tried to find food grade materials, since all of this was flowing into our organic garden. It adds a lot of cost to the build, but I think it was worth it in the end.

Parts

Connecting it all up

The main issue in connecting all the tubing is to make sure everything is adequately sealed. For most of the threaded fittings I used teflon tape to seal everything. However, when I finally had the whole system running, the pressure would rise as the barrel filled up, and then slowly drift back down. I suspect that because I didn't put teflon tape on the connections inside the project box, they were leaking.

Electronics box

Electronics box

The main requirement for the project box was that it be waterproof. Other than that, it just needed to be big enough to house all the electronics.

Parts

Electronics

Protoshield with pressure sensors

Parts

Sleep mode

To allow us to put the XBee to sleep, we need to have a pin on the Arduino connected to the sleep enable pin on the XBee. Because the Arduino we're using is running at 5 Volts, we need to be careful when connecting to the 3.3 Volt pins on the XBee. Sparkfun has a good tutorial on how to connect a 3.3V sensor to a 5V microcontroller. In this case, the XBee has a pull-up resistor available on the sleep enable pin, so we can use a simple diode. When the Arduino pin is high, the diode will block the current and the XBee pull-up resistor will pull the XBee pin high. When the Arduino pin is low, current will flow, pulling the XBee pin low as well.

Electronics in box

Software

Reading the sensor and reporting the data is relatively simple. The pressure sensors provide an analog voltage proportional to the pressure level, so this is read using an analog read on the Arduino. The XBee radio acts like a serial port, so we can use the standard Arduino serial port code to send the raw values. Because there's a possibility that the calibration of the pressure sensors will drift over time (See Freescale application note AN1636), I figured it was easier to read the raw values and perform the conversion to a pressure/level on the receiving computer. The code takes multiple measurements each sample period to average out any noise in the signal (Freescale application note AN1646).

The rest of the code deals with trying to save as much power as possible. I use the watchdog timer to control when to sample the sensors. Between samples I turn off as much functionality in the Arduino as possible as well as the XBee. The XBee wakes up after sampling the sensors and goes to sleep as soon as the data is sent. Most of the specific techniques were inspired by the Jee Labs work on low powered room sensors.

Status

The system continues to be plagued by two main problems. First after trying to seal the connections inside the box, I still have problems maintaining pressure at the sensors. The other issue is that the system still uses too much power.