Using a solar-powered Raspberry Pi to monitor greenhouse temperature
I bought a greenhouse at the start of this year, and since I had a spare Raspberry Pi lying around, I decided to repurpose it as a temperature monitor that I could use to make pretty graphs of the greenhouse temperature over time. The goal was to work out the earliest point at which it would be warm enough to leave plants in the greenhouse overnight, but mainly I just thought it would be a bit of fun :)
I started off with a Raspberry Pi 2, a portable phone charger for the power source, a WiFi dongle, a breadboard and a digital temperature sensor. I followed this guide to wire up the temperature sensor and write a python script to record the current temperature. I also modified the script slightly to update a JSON file with the latest reading. I then wrote a simple cron job to run the python script every 10 minutes and scp the JSON file to a second Raspberry Pi located in my house, which would then act as a web server to render the temperature graphs on a web page (I will put all this code on GitHub at some point!).
This worked well and I started to get some lovely graphs, but there was a small problem in that I had to periodically disconnect the portable phone charger to go and recharge it when it ran out of power. I ended up alternating between the phone charger and a 12V sealed lead-acid battery that I happened to have (combined with a cigarette socket adaptor that provided 5V USB ports), so that I could at least charge one battery while powering the Pi with the other one. Using a USB ammeter, I estimated that the Pi uses around 0.25A on average, so my 20Ah portable phone charger would last roughly 20 / 0.25 = 80 hours, or around 3 days. The 12V battery is rated at 17Ah, but you're not really supposed to drain sealed lead-acid batteries below 50%, so taking 8.5Ah as the 12V capacity, the equivalent 5V capacity would be (8.5 * 12) / 5 = 20.4 Ah, so basically the same as the phone charger i.e. 3 days. In reality, the phone charger lasted just over 2 days, so obviously there were other factors to take into account e.g. efficiency losses and the actual capacity being lower than stated.
So I would have to swap the batteries over no more than once every couple of days, but this still didn't quite satisfy my nerd urges; ideally I would just leave the Pi in the greenhouse and never have to touch it at all! So I ended up buying... a solar panel and solar charge controller from Photonic Universe to charge the 12V battery!
When calculating what size solar panel to buy, there are many variables: expected power draw, latitude, direction and angle of solar panel, expected number of hours of sunshine per day etc. The power draw was a tricky one to estimate because I didn't want to rule out adding extra greenhouse gadgets later e.g. fans, heating, irrigation etc. To power just the Raspberry Pi on its own and keep the battery sufficiently charged, in the north of England, a 20W panel should theoretically be enough, although possibly not during the darkest winter days. I decided to play it safe and get a 50W panel to go with my 17Ah battery. Slightly overkill to power a little Raspberry Pi, but hey :)
The solar charge controller is designed to be screwed to a wall in a boat or caravan, which obviously poses an issue for a greenhouse, since screws don't work well with glass. I didn't particularly want to glue anything to the glass, so I ended up fashioning a wooden base with two sides, to create a portable "wall" to screw the controller to. The two sides are screwed together for support, but they are connected to the base with just dowels; no screws or glue. This allows me to detach the sides from the base to make wiring easier.
The project got an unexpected boost when my friend John donated a MoPi that he wasn't using, which meant two things: first, I could now plug the Pi straight into the 12V load circuit of the solar charge controller (the MoPi accepts anything from 12V to 20V, rather than the Pi's usual 5V), bypassing the cigarette adapter and thus increasing efficiency; second, I could use the MoPi to turn the Pi off and on at set intervals, saving even more battery power! So now I have the Pi configured to turn on for 2 minutes, long enough to boot up and take a temperature reading (and let me ssh into it if there's a problem), then turn off for 8 minutes, and so on, reducing power usage by 80%.
So now I have pretty temperature graphs, and don't have to mess around with changing batteries every few days! Of course, I still go into the greenhouse to water the plants (automatic irrigation will have to wait until another time!), and occasionally check the charge controller to see the reassuring "battery full" indicator :)