Connecting a weather station to your Arduino

Lead Image © vectorshots,

Stormy Weather

After losing one weather station to tropical winds, the author reboots and designs a PCB that connects to an Arduino and monitors weather instruments.

As usual with SwitchDoc Labs projects, the tale grew with the telling. I started out building a simple interface from the SparkFun Weather Station Meters [1] to interface to Project Curaçao.

The project then morphed into a substantial upgrade. Project Curaçao is a wind- and solar-powered Raspberry Pi and Arduino project located in the Caribbean on the island of Curaçao. (For more information about Project Curaçao, check out the wind power article in a previous issue of Raspberry Pi Geek magazine [2].)

Why am I using an Arduino and not a Raspberry Pi? Three reasons: In Project Curaçao, the Arduino is on 100 percent of the time, whereas the Raspberry Pi is off about eight hours a day (for power considerations). I need a computer available to measure the wind 24 hours a day. Second, the Arduino has several available hardware interrupts, 10-bit analog to digital converters (ADCs), and lots of spare GPIO pins (by the way, the Raspberry Pi B+ adds a number of new GPIO pins). Third, I wanted to run these sensors at 5V for noise and distance considerations, rather than at 3.3V on the Pi.

My problem with Project Curaçao (aside from the destruction of the wind turbine one week after it was put up the tower; Figure 1) was that I had a wind turbine, but I couldn't tell how fast the wind was blowing. I could measure the voltage from the wind turbine, but the voltage depended on how much current the charging system was taking instantaneously. That meant the voltage would vary all over the place as the battery charged and discharged.

Figure 1: Destroyed wind turbine.

However, I knew the current into the battery and the voltage of the wind turbine, so I had the possibility of curve fitting some kind of solution to estimate the wind speed. I didn't think it would be too accurate unless I did a lot of characterization and data gathering. Of course, the voltage was zero after the turbine destroyed itself. I could measure that.

With all of this in mind, WeatherArduino was born: a printed circuit board (PCB) that is an interface between the SparkFun weather station meters and the Arduino. It is designed as a general interface for the weather instruments to the Arduino (and with a little work, the Raspberry Pi). Of course, I added some I2C bus components to address some other system issues.

Weather Instruments

The SparkFun unit consists of a wind anemometer, a rain bucket, and a wind direction gauge all connected to RJ11 connectors along with brackets, a mounting pipe, and screws (Figure 2). The anemometer measures wind speed by closing a contact as a magnet moves past a reed switch. A wind speed of 1.492mph (2.4km/h) causes the contact to close once per second. Counting the closings of the switch over a known time gives a measure of the average wind speed. Counting the shortest time between closings gives the highest wind gust in a given time. To count the number of clicks in a given sample time, I use a rising edge interrupt for the Arduino.

Figure 2: The SparkFun weather meter sensors.

The rain gauge measures the amount of rain via a self-emptying bucket. Each 0.011 inches (0.2794mm) of rain causes one momentary contact closure that is also connected to an additional rising edge interrupt on the Arduino.

The wind direction gauge is the most complex of the sensors. It has eight reed switches, each connected to a different resistor. The wind vane's magnet may close two switches at once, allowing the measurement of 16 different wind directions. However, in testing the unit, I never could make the device close two switches at once, so although it might be possible theoretically to measure 16 directions, I only get eight. The software takes 16 directions into account, just in case.

To measure resistance, I use a 10kohm resistor divider with one end tied to 5V (Figure 3). Then, I connect the middle of the divider to one of the pins of the Arduino ADC (I used A0), measure the voltage, and by referring to Table 1, convert to wind direction. All of this is done in the WeatherArduino library.

Table 1

Wind Direction Conversion Table

Direction (deg)

Resistance (ohms x 103)

Voltage (VCC=5V, R=10kohms)

















































*The value for 315 degrees in the manufacturer's datasheet is wrong; 4.34V is correct.

Figure 3: Resistor divider for measuring wind direction.

I use the 10-bit ADC included with the Arduino. Ten bits of resolution gives 5V/1024 bits = 0.005V/bit, which is enough to measure everything except the transition between 67.5 and 90 degrees. However, I never see 67.5 degrees (because only eight wind directions are recorded), so I just use a fuzzy search to pick out 90 degrees. The WeatherArduino PCB has provisions to hook up a 16-bit ADC to the I2C bus, but 10 bits works for this application; 16 bits gives 5V/65,536 bits = 0.00008V/bit, which can easily resolve all of the ambiguity in the wind conversion table. Every time I want a wind speed measurement, I call for a analog to digital measurement on Arduino port A0.

Additional Devices

The WeatherArduino PCB has three additional spaces for devices, including:

  • 1. DS3231 real-time clock (RTC). This I2C is inexpensive (US$ 8), highly accurate, and temperature-compensated. The DS3231 replaces the DS1307 RTC in Project Curaçao because of reliability issues with the DS1307. Arduino libraries for the DS3231 [3] are available online. (In the SwitchDoc Labs column of this issue, I discuss how to use an I2C bus  [4]; in the next issue, I'll compare four different RTCs, including the DS3231.)
  • 2. Adafruit 32KB FRAM I2C. I added this I2C to the board to provide additional storage for the Arduino Mega 2650 to store readings during the night when the Raspberry Pi is not powered on. The readings are sent in the morning to the Raspberry Pi, which then stores them in a MySQL database. Arduino libraries for the 32KB FRAM are available on the Adafruit GitHub site [5], and a Python driver for the Raspberry Pi is available on [6].
  • 3. Adafruit ADS1115 16-bit ADC. I added this highly accurate ADC in case the wind gauge needed it (it did not) or to add the vibration sensor. (As of this writing, the jury is still out on that one.) The Arduino libraries for the ADS1115 also reside at the Adafruit GitHub site [7].

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content