Building a weather station.

28 April 2023

Note: There are some affiliate links in this post. You don't have to buy stuff with them if you don't want to.

One of the things I always wanted to build was a weather station. For some odd reason they always struck me as being intrinisically neat; sensors that could tell you about what was going on outside when you couldn't be outside yourself. Many years later when I got into amateur radio, I discovered that weather stations were a thing that people would build and put on the APRS network to broadcast local weather conditions. Thing was, I never quite had the time or knowhow to build such a thing. Then, after working from home for the last couple of years and losing my job in January, I figured "fuck it" and decided to sit down and do it.

It started out innocently enough, by buying a fairly simple weather meter kit that's decently well documented and has a datasheet available. A little bit of research produced this particular project which I wound up making quite a bit of use of. Enough use that I found a couple of bugs in the schematics and had to troubleshoot them myself. Irritating and annoying, to be sure, but I also learned a couple of things, which was the entire point of the project. To round things out I also ordered a couple of BME280 multi-sensors and some analog/digital converter chips from Adafruit to get a bit more crunchy data, vis a vis temperature, humidity, and air pressure. It's probably not enough for weather forecasting, but for doing reasonably basic trend analysis it suffices.

I am not the world's greatest electrical engineer. On a good day I might be considered an adequate one. But I'm working on it, one project at a time. And this particular project wound up being interesting, frustrating, and rewarding. It was also an exercise in patience because I couldn't just sit down and bang everything out in the space of a weekend. Much of the project's time wound up being "work on something for an hour," "go outside and measure stuff," "go outside and drill some holes," "do some research while the silicone sealant sets," and so forth. In other words, do as much as I could while I could and then cool my heels until the next thing I could poke at arrived.

There was also an unusual amount of reverse engineering that had to be done. While waiting for parts to come in I took apart the kit's sensors (anemometer, weather vane, and rain gauge) a couple of times to see how they worked and get a sense for how to hook them up. Because, as we all know, I love following instructions to the letter.

The thing that I find striking about so much of the weather station is that it's basically a bunch of switches. 1 The anemometer is a cluster of reed switches, switches that close (in this case) when a magnet gets close to them. Count the number of times the switch closes in a certain period of time and you can calculate how fast the arms of the anemometer are moving, which is also how fast the wind is moving. Same with the rain gauge; every time every so much rain is collected by the gauge it tips over to empty and closes a switch. Count the number of times the switch closes in a certain period of time, multiply by a known amount of rain and you know how much rain has fallen. The weather vane works along similar lines but proved to be more of a challenge due to an error in the schematic.

There are eight basic directions: North, south, east, west, northeast, southeast, southwest, and northwest. One switch for each in the weather vane, but only two wires for all of them. But how?

Each switch, when it closes, cuts in a resistor with a unique value to limit the current passing through it. This means that each switch corresponds to a different voltage. For example, when the weather vane is pointing north 1.0 volt goes down the wires. When the weather vane is pointing west, 2.6 volts goes down the wires. And so forth. Measure the voltage, look up the direction it corresponds to, and you know which way the wind's blowing.

To save some folks some effort here's the table I built when I had the weather vane opened up and was poking around with a multitester:

direction resistance (ohms) voltage (3.3V, 10k)
N 33k 1.0v
NE 8.2k 3.0v
E 1k 2.8v
SE 2.2k 2.9v
S 3.9k 2.5v
SW 16k 1.4v
W 120k 2.6v
NW 64.9k 1.1v

To pick up each of the eight different voltages a chip called an analog/digital converter is used in the circuit. Without getting too technical about how they work, each of those voltages is an analog signal: 1 volt is 1 volt is 1 volt. It doesn't change as it moves through the wire (for the sake of discussion). The A/D converter samples whatever signal comes in over its input pins a few thousand times per second and outputs a digital signal (one of two voltages representing a 0 or a 1) to one of the input pins on the Raspberry Pi that I used to use as my jukebox. To do this properly, however, I had to build a small circuit called a voltage divider to make the signal coming from the weather vane easier to detect and interpret. Referring to the image on Wikipedia, a current goes through one resistor (Z1) (one of the eight resistors in the weather vane) and goes into the sampling pin on the A/D converter. At the same time there is a second resistor (Z2) that doesn't change value which pulls on that current at the same time and steals some of it. Because you know the voltage you started with (3.3 volts, in this case 2), and you know the values of the two resistors, you can calculate how much voltage the sensor pin is going to see:

output voltage = (second resistor / (first resistor + second resistor)) * input voltage

This was not correctly specified in the project writeup. They got the math wrong. The other thing they got wrong is that, when you have a voltage divider the thing that samples the current goes between the resistors and not upstream or downstream of them. That took a while to figure out.

A couple of trips to the hardware store produced a mast to mount the thing on (a 10 foot length of 1.5" PVC pipe cut in sections for modularity), compression couplings to fit the pipe segments together, end caps to keep water out, and a power junction box designed for outdoor use to protect the sensitive stuff. I also ordered a box of assorted glands for the sides of the junction box. I don't know why they're called that and I probably won't call them that around my in-laws but they basically let wires pass through holes while making it difficult for water and dust to get in. The real selling point there was the 1.25" glands in that kit which were ideal for running an outdoor extention cord's female end into the junction box. I bought an extension cord with transparent plastic ends specifically for this because I knew that I needed to carve the plastic down a little bit so it would fit through the gland. Transparent plastic is the key because I could make sure that I wasn't removing too much and exposing anything carrying house current. Final assembly involved running the whittled down power connector through the gland into the box, cranking the outside fixture of the gland down to tighten it, and letting the power connector rest however it wanted to, which wound up turning it into a mounted power outlet, basically. I made sure to squirt a bunch of silicone sealant into the gland and around the power connector to weatherproof it and generally glue everything into place. I'm weirdly pleased with how that turned out.

I designed pretty much the whole thing to use zip ties for mounting in the back yard, which seems to be working very well. An early step of modifying the junction box was to mount some conduit fittings on the back (suitably weatherproofed with silicone sealant 3) that I could use for creative application of zip ties. The bottom of the mast is resting on the deck but it's braced with zip ties. When standing the mast up it was decided that one of the three segments should probably not be installed for safety purposes but the compression couplings I used made it easy to remove one segment of pipe. I tried to cement the endcaps on but for some reason none of us were able to get the cans of primer or cement open for anything. I wound up tossing them. Some creative positioning of pipe clamps attached the weather sensors to the mast, with yet more zip ties making the wiring neat.

I also discovered that the anemometer didn't have a long enough cable. It was originally designed to plug into an RJ11 jack in the bottom of the weather vane but I'd already decided to do something different and had desoldered the jack from that other sensor's board to make it easier to reverse engineer. Due to not being able to find any locally (because who actually runs phone line anymore?) I had to order some phone line rated for exterior use, and it's basically CAT-6 network cable. Those were definitely not RJ11 plugs on the ends. However, a pair of bolt cutters and some creative bladework later and I'd exposed one pair of wires suitable for replacing the too-short cable. It's remarkably rigid stuff and running it required working with the way the cable was already tending to bend rather than forcing it.

Incidentally, I'd originally ordered a handful of RJ11 jacks because I was going to use them in the circuit I was building. Either the jacks were wrong (possible) or the plugs on the sensors' cables' ends are not RJ11. Either way, bare wires and some screw terminals work just as well. It's kind of weird that the really nice screwdriver set I have doesn't have bits that fit those screws, but the crappy knockoff does. Go figure.

The thing I've been working on most lately has been software to drive the sensors, pull data, and do stuff with it. Shockingly, it's part of my exocortex and has a somewhat dumb name, Weather Bot. I've got it at a proof of concept stage, where it's running my weather station, monitoring the sensors, doing basic statistical analysis, and sending alerts over an XMPP bridge when something interesting happens. I've also got a basic "write the last set of sample data to a file" module implemented. My eventual goal is to add modules to send readings to Open Weathermap, Open Sensemap and the Citizen Weather Observer Program among other citizen science projects. I've also spent some time setting up InfluxDB and Grafana so Weather Bot will soon be able to write data to a local database for analysis on a dashboard.

If you want to look at some of the pictures I took during the build process, here they are.

  1. The BME280 I did not take apart and analyze, so I cannot confidently say that it is another bunch of switches. 

  2. The Raspberry Pi's GPIO pins should really only be used with 3.3 volts. There is the possibility that using 5 volts can damage the unit, and given how difficult it is to find them these days it's probably not a good idea to risk it. 

  3. I love this stuff. It's like universal glue.