Rain Barrel (2010)¶
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.
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.
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.
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.
Flexible copper tubing. This is the tubing I used inside the barrels. It's usually used for things like running water to an ice maker. Basically, it's flexible copper tubing that comes in a coil and can be bent by hand. McMaster-Carr #8955k31 (I had some scrap available, so this might not be exactly the right part number.)
Compression fitting, used to connect the flexible copper to the through-wall barbed fitting. McMaster-Carr #5272K181.
Through wall pipe to tube adapter. This fitting is designed to mount through the wall of an enclosure. It provides a barbed connection on the outside to connect to the neoprene tubing. On the inside it has a pipe fitting. These are used both on the barrels as well as the electronics project box. McMaster-Carr #2974k821.
Neoprene Tubing. This is the main tubing used outside of the barrels. It's UV-resistent and food safe. If you're willing to use PVC, you can get something a lot cheaper. McMaster-Carr #52035k16
Pipe to tube adapter. A barbed fitting without the flange and nut needed to mount through an enclosure wall. These probably aren't needed, since the through wall versions would work in their place. McMaster-Carr #5116k86
Pipe coupling. I couldn't find any way to get a through wall fitting with barbs on both sides, so I used this coupling with two barbed-to-pipe fittings to make my own. It makes for a much longer fitting than I'd like. McMaster-Carr #4464k212
Hose clamps. These are used to secure the neoprene tubing to the barbed fittings. They're plastic so they won't rust, but I managed to break a couple trying to get them tight. McMaster-Carr #5246k61
Thread sealant. Used to seal the connections, usually Teflon tape or pipe dope. Easy to find at your local hardware store. McMaster-Carr #4591k11
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.
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.
Pelican 1050 Case. This is the box for all the electronics. It's designed to be waterproof, and the clear plastic should make it easy to monitor the electronics inside. REI 778217
Breather vent. I was worried that the electronics box was air tight. Since I wanted to make sure the box was at the same pressure as the outside air, I added a breather vent. McMaster-Carr #4471k11
Nut for breather vent. This is a nut to secure the breather vent inside the project box. McMaster-Carr #91862A101
Freescale MPX5010GP Pressure Sensor. This is the main sensor to measure the pressure. Digi-Key MPX5010GP-ND
Arduino. I used an Arduino Pro 5V. There are lots of other available options. Sparkfun 9219
Prototyping board. I used a Sparkfun version meant to be used as a shield for the Arduino. Sparkfun 7914.
XBee break out board. Some way to connect to the XBee. The version I used has a voltage regulator go to from 5V to 3.3V as well as the logic to correctly interface the 5V signals from the Arduino to the 3.3V logic levels of the XBee. Sparkfun 9132.
XBee 1mW with Chip Antenna. This is the wireless radio used to send sensor values back to a computer. Sparkfun 8664.
6 pin, right angle socket. This is used as a socket for the pressure sensors. This makes it a lot easier to keep the sensors connected to the tubing when removing the electronics from the box. Digi-Key S5481-ND.
Capacitors: 0.01 uF, 1.0 uF, 0.33 uF, and Resistor: 750 Ohms. These are all used for filtering the power to and the output from the sensor.
Diode. Used to convert the signal level for controlling the XBee sleep mode. Digi-Key 1N5818-TPCT-ND.
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.
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.
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.