Come rain or shine, a Raspberry Pi weather station makes a great project. With a budget of around $100, Peter Kodermac built a Pi-powered weather station that captures temperature data, graphs it, and publishes it online. His website provides step-by-step instructions to walk you through the process, which involves some simple wiring, and setting up the Raspberry Pi as a web server.
For the Raspberry Pi weather station sensor, Peter recommends the DS18B20. It’s waterproof and comes with a long cable so you can keep the sensor away from the weather station, which might generate heat. The DS18B20 doesn’t measure humidity, so if you want to track humidity, try the DHT22 instead. Peter warns that the DHT22 tends to give less consistent values and can take more than one attempt to get a reading. Peter’s code, available through GitHub, is designed to compensate for that, automatically retrying where necessary.
Peter uses a Pi Cobbler breakout cable and a breadboard to make it easy to connect the sensor to the Raspberry Pi. Make sure you buy the correct Cobbler cable for the model of Raspberry Pi you are using! Everything is housed in a plastic food box, with a hole for the power cable to go in, and for the sensor cable to come out. A wooden roof offers shelter, and Peter puts silica gel sachets inside the box to offer additional protection from moisture.
Raspberry Pi weather station circuit
The DS18B20 is a waterproof temperature sensor that gives consistent and fast results. You could use the DHT22 sensor instead, which also measures humidity
The Pi Cobbler breakout cable connects all the GPIO pins to the breadboard, making it easy to connect the sensor to the pins on the Raspberry Pi
The plastic box protects your Pi from the rain. The plastic lid and wooden roof are not shown here. This Pi is externally powered, but you could use a sealed box with a battery inside
Setting up the Raspberry Pi weather station
There were several stages involved in setting up the software for Peter’s Raspberry Pi Weather Station. First, he installed MySQL and used it to create a database for WordPress, which he uses to store the weather data. Then he installed and configured Apache and WordPress. He installed the Raspberry Weather plugin for WordPress, to generate a graph of the latest temperatures when anybody viewed the webpage. Finally, he used a Python script to query the sensor and put its data into the database, and Cron to schedule the script to run every 30 minutes. “The whole process of setting up a web server can be a bit frustrating at times, but it is totally worth the time and effort,” Peter says. “It’s just so great to build your site from scratch and see other people visit it and give you feedback!”
Peter has run the project on almost all versions of the Raspberry Pi. “WordPress is a bit of a memory hog, so the website loads more slowly on the Pi Zero, or older versions of the Pi. That’s why I also included a neat caching trick to speed up things a bit.”
You can also monitor the results on your Android phone, using an application called My Weather Station. It displays the latest data from an XML file, which is updated in parallel with the main WordPress database.
Since Peter shared his weather station design, other makers have added cameras, wind-speed and air-pressure sensors, and are calculating forecasts. If you build one, let Peter know. “I have always felt great pride in publishing links to the people who have completed the guide,” he says. “I get a nice fuzzy feeling when other people improve my code, too – all thanks to open source.”
Three Weather Station Projects for Raspberry Pi
- Even if you don’t have a weather station, you can access the database of Pi Weather Station readings, and use it to plot temperatures on a map using Python.
- The official Weather Station HAT is being used by schools to record data, including humidity, pressure, and air quality readings, in an Oracle database
- Use Scratch to display your weather data, including a thermometer, along with a visual indicator for wind speed and direction. A Python script is used to feed the data to Scratch.
Win! One of ten PaPiRus Zero Screen and Case kits. Click here to enter.