4 weeks ago

Raspberry Pi summer projects part 1

Summer’s here, so why don’t you unplug your Pi and go outside? Use a battery pack to take your Pi with you, of course! In this issue, we celebrate the great outdoors with twelve ideas you can use to make the most of the (hopefully) good weather. You’ll see how to build a weather station, how to launch a high-altitude balloon with a Raspberry Pi tracker, and how to photograph the wildlife in your garden with hidden Pi-powered cameras. If you’re a sporty type, we’ve got some upgrades for your bike or skateboard too. Let’s go!

Build a weather station

You’ll need

  • Raspberry Pi
  • Breadboard
  • DS18B20 or DHT22 sensor
  • Plastic box
  • 4.7 kΩ resistor
  • Adafruit Pi Cobbler breakout kit (26- or 40-pin)

Protect your Pi from the rain. The plastic lid and wooden roof are not shown here.

Come rain or shine, a weather station makes a great project for your Raspberry Pi. 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 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.

Connecting the sensor to the Pi. Image: Simon Monk (CC-BY 3.0)

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.

There were several stages involved in setting up the software for Peter’s project. 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.”

Weather station projects

Make a weather map

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.

Use the Weather Station HAT

The official Weather Station HAT is being used by schools to record data, including humidity, pressure, and air quality readings,
in an Oracle database.

Report the weather in Scratch

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.

Look out for part two and more projects later this week!