I like to play around with my Raspberry Pi and see what I can do with it. Recently I got it to stream video from a webcam and show it on the streaming website www.ustream.com: this will eventually become a home CCTV system. In the next week or two a signal generator I ordered will have arrived, and I’ll use the RPi to control it and encode Morse code onto the signal, which will then be sent to an amplifier, a filter, and finally an antenna to act as a low power QRSS radio beacon.

This week, however, I built a weather station.

I had an AM2302 temperature and humidity sensor lying around so this afternoon I decided to actually use it and see what I could do with the Raspberry Pi. I quickly found these simple instructions on the Adafruit website so I pulled out some prototyping breadboard, some connector cables, and a 4.7kOhm resistor. The circuit was assembled in minutes, and the software and dependencies required were downloaded and installed easily. The most difficult part of the process was setting up OAuth2 so the Pi would connect to Google Docs and upload the collected data. Though even that part wasn’t difficult: just follow the instructions carefully as far as downloading your JSON file, and the Adafruit instructions tell you what to do from there. I use my Raspberry Pi headlessly so I used WinSCP to copy the JSON file to the Pi from my laptop after downloading it.

The test scripts worked straight away, and within a few minutes of setting up everything I was uploading data to Google Docs. You can check out today’s test run here.

Temp and Humidity

Graph of temp and humidity. Note the spike in humidity when it rained between about 14:10 and 14:20.

This was a successful run that experienced no issues. At this point I’m considering an extended test over several days to see how it performs.

Next up to try was a rain gauge. I bought a second-hand weather station from a friend a couple of years ago. While I was able to get the system to work and upload data while it was wired to the datalogger connected to a PC, it stop working after a short while when this was attempted wirelessly. I still have all the gear, however, which may come in useful on this project.

I disassembled the housing of the rain gauge to check the wiring and to clean it out: it had been outside for some time so I correctly assumed it would be full of dead bugs and other debris. A rain gauge operates surprisingly simply: there is a see-saw mechanism inside onto which water drips down. When a certain amount of water has fallen onto it, it rocks over and the bucket empties, allowing the other side of the see-saw to be filled. There is a magnet attached to the mechanism, and a reed switch in the tower next to it. When the magnet passes the switch, the circuit closes and allows electricity to flow through it as a pulse. If you know how much water the bucket can hold, you simply multiply the number of pulses by this amount of water to find how much rain has fallen. For example, if a bucket on the see-saw holds the equivalent of 0.5mm of rain, and it rocks over six times, then that’s a rainfall of 3mm (0.5mm x 6 pulses).

Rain gauge (without cover) connected to weather station board. Note the jumper leads soldered to the circuit and connected to the 3V3 and GPIO pins of the RPi.

Rain gauge (without cover) connected to weather station board. Note the jumper leads soldered to the circuit and connected to the ground and GPIO pins of the RPi.

I found an interesting blogpost about using a rain gauge with the Raspberry Pi here, and got mine hooked up easily after soldering some jumper leads to the reed switch circuit. Unfortunately, rocking the see-saw mechanism did not show a result on screen when running the code the author of that post linked to. I have a feeling that the reed switch itself might be jammed or dirty, so I will have to inspect the circuit further and possibly replace it. On the plus side, however, the code again runs easily and outputs data into a CSV file. I think some minor modifications to both this code and the temperature/humidity sensor code will allow me to output all measurements into a single file with a timestamp for easy plotting and uploading.

I have the BMP180 pressure sensor on order. When this arrives I’ll add it to the system, which will result in an air pressure metric on the graph above! Once it starts collecting data I might be able to have the code guess when it’s raining, etc., based on the data it collects. Once that’s all running I’d like to have a Raspberry Pi set up somewhat permanently and uploading data to a webserver, where further code will generate graphs and insert information into a webpage so visitors can view the weather information.

Watch this space over the next few weeks for more updates!