How to Build a Raspberry Pi Weather Station

By Arvind Sanjeev

 

A few months back, I was wondering how weather stations work. How do they acquire and display data? I decided it would be a great IoT project to make.

I did a little research and found some commercial systems I could base mine off, as well as some online tutorials to help with some of the sensor or Raspberry Pi concepts.

 

 

This is a complete Raspberry Pi weather system with just the base Raspberry Pi hardware, camera, and some assorted analog and digital sensors to make our measurements. No buying pre-made anemometers or rain gauges — we are making our own! 

Features:

  • Records information to RRD and CSV, so it can be manipulated or exported/imported to other formats
  • Uses the Weather Underground API to get info like historical highs and lows, moon phases, and sunrise/sunset
  • Uses the Raspberry Pi Camera to take a picture once a minute (which you can use to make time-lapse videos)
  • Has webpages that display the data for the current conditions and some historical conditions (last hour, day, seven days, month, year)
  • The website theme changes with the time of day (four options: sunrise, sunset, day, and night).

 

All of the software for recording and displaying the information is on Github and is open source.

This project was a great learning experience for me. I got to really dive into the capabilities of the Raspberry Pi, especially with the GPIO, and I hit some learning pain points as well. I hope you can learn from some of my trials and tribulations.

 

 

Required Materials


Electronics

  • 9 Reed Switches (8 for the wind direction, 1 for the rain gauge, and 1 for the wind speed (optional) instead of a Hall sensor — I used these
  • 1 Hall sensor (for the wind speed, called an anemometer)
  • Temperature sensor
  • Humidity sensor (many humidity sensors come with a temperature sensor), I used the DHT11
  • Pressure sensor (the BMP came with a temperature sensor in it as well), I used the BMP180
  • Photoresistor
  • GPS Chip or USB GPS
  • 4 strong magnets (2 for anemometer, 1 for direction, 1 for rain gauge) — I highly recommend rare earth magnets
  • A handful of assorted resistors — I have this pack which has proved extremely handy over time
  • MCP3008 to convert analog to digital inputs for the Raspberry Pi 

Hardware

  • Raspberry Pi — I used the B+
  • Wireless adapter
  • Pi Camera
  • A solid 5V power adapter — This turned out to be painfully annoying. I eventually got this one, otherwise the camera pulls too much juice and can/will hang the Pi.

Materials

  • 2 thrust bearings (or skateboard or roller-skate bearings will work too)
  • 2 waterproof enclosures — I used an electrical enclosure from the local big box store. It doesn’t matter much, you just need a good-size enclosure with enough space and ability to protect everything.
  • Some PVC pipe and end caps (various sizes)
  • PVC mount brackets
  • A couple of sheets of thin Plexiglass (nothing too fancy)
  • Plastic standoffs
  • Mini screws (I used #4 bolts and nuts)
  • 2 plastic Christmas tree ornaments — For the anemometer. I got mine at the local Hobby Lobby.
  • Small dowel
  • Small piece of plywood

Tools

  • Dremel
  • Glue gun
  • Soldering iron
  • Multimeter
  • Drill

Enclosure

The main enclosure houses the PI, the camera, the GPS, and the light sensor. It is designed to be waterproof, since it houses all the critical components, and the measurements are taken from the remote enclosure, which is designed to be exposed to the elements.

Enclosure contains:

  • The Raspberry Pi (on standoffs) — Needs a Wi-Fi chip. Don’t want to be running Cat5e into the backyard!
  • The camera (also on standoffs)
  • The GPS chip, connected via USB (I used this FTDI cable) — The GPS provides latitude and longitude, which is nice, but more importantly, I can get accurate time from the GPS!
  • 2 ethernet/cat 5 jacks to connect the main enclosure to the other enclosure that houses the other sensors. This was just a convenient way of having cables going between the two boxes. I have roughly 12 wires, and the two cat5 provide 16 possible connections, so I have room to expand/change things around.

 

Enclosure for Temperature, Humidity, and Pressure

 

 

This is where I stored the temperature, humidity, and pressure sensors, as well as the hook ups for the rain gauge, wind direction, and wind speed sensors.

It’s all very straightforward. Pins here connect via the ethernet cables to the required pins on the Raspberry Pi.

I tried to use digital sensors where I could, and any analog are added on to the MCP 3008. It takes up to 8 analog, which was more than enough for my needs, but gives room to improve/expand.

This enclosure is open to the air — it has to be for accurate temperature, humidity, and pressure. The bottom holes are popped out, so I gave some of the circuits a spray of a Silicone Conformal Coating spray (you can get it online or a place like Fry’s Electronics). It should protect the metal from any moisture, though you have to be careful not to use it on some of the sensors.

The top of the enclosure is also where the wind speed sensor fits. It was a toss up — I could have put the wind speed or wind direction on top, but I didn’t see any major advantages of one over the other. Overall, you want both sensors (wind direction and speed) high enough so buildings, fences, and other obstacles don’t interfere with the measurements.

 

Making the Rain Gauge

 

I mostly followed this tutorial on Instructables to make the actual gauge.

I made this out of plexiglass. Overall the plexiglass worked okay, but combined with the glue gun, rubber sealant, and overall cutting and drilling, it doesn’t stay looking pristine, even with the protective film.

Key points:

  • The sensor is a simple reed switch and magnet treated like a button press in the Raspberry Pi code. I simply count buckets over time and later make the conversion to “inches of rain.”
  • Make it big enough to hold enough water to tip, but not so much that it needs a lot in order to tip. My first pass, I didn’t make it large enough, so it would fill and start draining over the edge before it tipped.

 

 

Wind Direction

 

 

 

This was simple.

Key Points:

  • This is an analog sensor. The eight reed switches combined with various resistors divide up the output into chunks so I can identify which coordinate the sensor is in by the value. (The concept is explained in this tutorial on Instructables.)
  • After screwing on the weather vane part, you need to calibrate it so “this direction is what points north.”
  • I made a test rig with wood so I could switch resistors in and out easily that covered the full range of values for me. That was super helpful!
  • I used a thrust bearing, which worked fine.

 

Software

 

The software is also open source and is available on the same GitHub repository.

 

 

Software is written in Python to record the data from the sensors. I used some other third-party Git libraries from Adafruit and others to get the information from the sensors and GPS. There are also some cron jobs that pull some of the API information. Most of this is explained in the Git documentation at docs/install_notes.txt.

The web software is in PHP to display it on the webpage while also utilizing YAML for the config files, and, of course, the RRD tool to store and graph the data.

It utilizes the Weather Underground API to get some of the interesting data that sensors can’t pull. Record highs and lows, phases of the moon, sunset and sunrise times, and tide information is also available on their API.

All of it is available on GitHub, and is actively maintained and currently being used as I further refine and calibrate my own system, so you can submit feature requests and bug reports as well.

The software changes themes depending on the time of day. There are four stages. If the current time is plus or minus two hours from sunrise or sunset, the sunrise or sunset theme will display.

 

 

Related Articles

 

Recommended Posts

Leave a Comment

− 1 = 1

Start typing and press Enter to search