This last few weeks, in my copious free time, I started building a wireless pool temperature monitor. Why, you may ask?
- I wanted to learn more about wireless communication with a Xbee, which speak Zigbee.
- I wanted to have something to do with the 3.3 V 2650-based “mega” Arduino boards I bought over a year ago.
- I wanted to know when I can go swimming.
- A Mega Pro Mini 3.3V Arduino from Sparkfun Electronics. Make certain you get the proper connectors!
- A Xbee 2.4 GHz S2B model Zigbee radio from Digi International (http://www.digi.com/)
- A Breakout Board for XBee Module to make it easy to use the XBee modules without soldering directly, also from Sparkfun Electronics. Don’t forget the 2mm 10-pin headers!
- Three Dallas DS18B20-PAR One-Wire Digital Thermometer.
- One Dallas DS18S20 Digital Thermometer.
- A 2-cell AA-size battery holder. I plan on making this a self-sustaining solar install – eventually, but for now it seems to be running for 6 days on these cells. I do plan on using a DC-DC converter of some sort to drive it off more easily acquired, mainstream solar powered sources.
- Temperature probe assemblies.
The Arduino, battery, and XBee are inside a waterproof plastic box, with a hole cut on the side with a water-resistant right-angle connector hanging off the side. I am using some reclaimed CAT-3 cable. The DS18S20 is soldered on a small board, right next to the XBee’s adapter, so I can monitor the temperature of the box as well as the pool.
To build an insanely over-engineered waterproof probe with three sensors, I used some 1.25 inch schedule 40 PVC tubing I had lying around, which was slightly longer than the pool is deep, measured from the top of the pool’s wall. I then cut this in half, and drilled three holes: one near the top of one of the halves, and two holes near both ends of the other. I put these far enough down so I can use a coupler and install an end cap on the in-pool end, and a 90 degree bend on the other.
I then tapped each hole I drilled, and inserted a stainless steel bolt which is long enough enough into the tube to allow me to epoxy the DS18B20-PAR in place on the end of the bolt. Just to be safe, I also eventually covered this whole mess with silicone.
After putting on an end-cap, using the coupler to make one long probe, a right-angle and more pipe to bring it over the pool’s top, it is clamped in place, with the wire running to the Arduino box.
(Pictures coming later, when it’s not raining!)
- A XBee Explorer USB from, you guessed it… Sparkfun Electronics.
- A XBee S2B with an RPSMA antenna connector, which currently houses a small RPSMA antenna I repurposed from an ancient wireless network camera.
This is plugged into my laptop currently, but I plan on using a spare wireless router I have on hand, after modifying it to have Ruby (yes, Ruby) installed. It will record data, and transmit it to my off-site host. I hope to let it record enough data that, should the network be down for a few days, nothing is lost.
The software consists of three primary applications: the Arduino code, which runs on the sensor node; the Ruby code to receive data from the in-house XBee; the code to graph all of this stuff.
I am interested in comparing data year-to-year, so a long-duration data store is important. Rather than re-invent the wheel, I chose to use a bit of software I have used often in the past: rrdtool. I have multiple stats that I record, temperature from the 4 external sensors, local and remote RSSI indications, and local and remote voltage, measured from the XBee devices via AT commands.
The Arduino software is careful to conserve power as much as possible. It lowers the clock down to the slowest setting possible using the system clock pre-scaler. It sleeps, waiting for a timer interrupt to wake it. With the configuration I have, this occurs roughly every 3.5 seconds. I then count these events, and once every 60 seconds or slightly less, the Arduino’s clock is returned to 8 MHz, the one-wire sensors are read, the XBee is awakened from its sleep, and the data is transmitted. Once every 10 minutes or so, the One-Wire bus is re-probed to detect new or missing devices, although I may remove this part, or only do it via remote command, or reset.
After the transmissions are complete, a short (100ms) delay occurs just to ensure any remote AT commands have made it to the XBee, and it is put to sleep again. The clock is then slowed down, the timer is re-armed, and the Arduino once again sleeps.
The receiver is written in Ruby. It opens the USB Explorer, and receives API-formatted packets. Each time a new sensor reading is received, it sends two remote AT requests to ask the remote end its RSSI reading and voltage, and then records the sensor readings to individual RRD files. When the RSSI and voltage reports are received, they are also written to RRD files.
The simplest of all! These just use rrdtool to graph the data, in various time scales.
Real-time graphs. Yay!