Mast – Temp & Humidity Sensors

To start off, I wanted to say that I know there are other sensors that can do what the sensors that I use can do and possibly even do it better, but I’ve had these two sensors for several years now and they have done exactly what I’ve needed them to without fail.

For temperature I use a DS18B20 and for humidity I use a Honeywell HIH-5031.  The DS18B20 is a very popular temperature sensor which uses the 1 wire protocol.  the HIH-5031 is an analog humidity sensor that runs on 3V.  The DS18B20 outputs a temp in C with the Arduino code, but the HIH-5031 only outputs a voltage which requires some code to translate into humidity.  I’ll post all of that later when I post about the code I use on the Raspberry Pi.

Sensor Wiring:

For wiring these sensors, each has 3 pins, a power, ground & read pin.  Because each sensor really needs to be exposed to air to reach correctly, I soldered several single wires to their pins and then used shrink tube to cover the connections and then another piece of shrink tube to collect the 3 wires together and cover a bit of the end of the sensor.  (You can see this in the pic above)  The two sets of 3 wires are brought together into a single cat 3 cable (4 wires).  I wire the power of each sensor to a red wire, the ground of each sensor to a black wire, then the read pins of each sensor to it’s own wire.  This allows me to be able to have only 4 wires in the wiring harness for these two sensors instead of 6.


Sensor Mounting:

As you can see above, I use an offshoot of my main mast to hold these two sensors.  The sensors themselves sit within a piece of 1 inch PVC that has holes drilled in it to allow for air flow.  This is covered with a 3″ PVC pipe that protects from solar radiation as well as rain.  I don’t have many of the details on all the PVC connections I used to make this happen, but all I did was go to the hardware store and start piecing things together to get what I wanted.

In a previous post I mentioned that I would make a separate post regarding the micro controller wiring as well as the wiring harness.  Again, for the micro controller I am using an Arduino Pro Mini 3V.  Below are a few pics and wiring details:

Microcontroller Pics:

A few pics of the micro controller wiring and waterproofing tube.  As you can see in the below pic, the micro controller sits within some 3/4″ PVC with caps on each end that have holes for the wires to come out of.  My suggestion would be to make the “top” hole waterproof by putting silicon or something around the cat 5 cable coming out and leave the bottom one free to slide in case you need to get to your micro controller for repair reasons.

Micro Controller Wiring:

I’ll include the micro controller pin as well as the wire color and “direction” of wire in this format: Pin on Pro Mini – Wire/direction – (wire color.)  (Some will have multiple wires attached)

  • Raw – 5V from RPi – (blue)
  • GND – GND from RPi – (blue-white)
  • A4 – SDA from RPi – (green)
  • A5 – SCL from RPi – (green-white)
  • Vcc
    • Power to wiring harness – (brown)
    • 4.7k Ω resistor for DS18B20 to Pin 10
  • GND
    • Ground to wiring harness – (orange)
    • Ground to wiring harness – (brown-white)
    • 65k Ω resistor for HIH-5031 to Pin A2
  • A1 – read pin for wind vane in wiring harness – (green)
  • A2
    • read pin for HIH-5031 in wiring harness – (orange-white)
    • 65k Ω resistor for HIH-5031 to GND
  • D2 – interrupt for rain gauge in wiring harness – (blue-white)
  • D3 – interrupt for anemometer in wiring harness – (blue)
  • D10
    • read pin for DS18B20 in wiring harness – (green-white)
    • 4.7k Ω resistor for DS18B20 to Vcc

Wiring Harness Pics & Wiring:

The wiring harness is where all the wires from the sensors come together with the wire coming from the Pro Mini.  I solder the wires together and use shrink tube to protect them, but I ran out of shrink tube and had to use these other connectors…don’t use these connectors.  It’s a mess…

For the wiring, I’ll list the wire color coming out of the micro controller and what wires are attached to it from the sensors.

  • Brown-white
    • GND for rain gauge
    • GND for anemometer
  • Brown
    • These two are tied together and I’ll explain in another post
      • 3V for DS1B20
      • 3V for HIH-5031
    • 3V for wind vane
  • Blue-white
    • 3V for rain gauge
  • Blue
    • 3V for anemometer
  • Green-white
    • read pin for DS18B20
  • Green
    • read pin for wind vane
  • Orange-white
    • read pin for HIH-5031
  • Orange
    • These two are tied together and I’ll explain in another post
      • GND for DS1B20
      • GND for HIH-5031
    • GND for wind vane


With this post I wanted to do a full overview of my mast, which I’ve spoken some on before. This will provide instructions on how to build as well as archiving things in case I need to rebuild it in the future. (I just had to re-wire everything and it was pretty difficult remember and figuring out where everything went) The mast is only one part of my weather station; the enclosure, which houses some other sensors as well as the RPi, will be in another post. The way my weather station works is the mast gathers info from the 5 sensors that are contained on/in it via the micro controller. It then sends the data to the Raspberry Pi that resides in the enclosure via I2C to be archived, along with data from the other sensors, within my database tables.

The mast is built out of PVC. This allows me to attach my homemade sensors easily as well as protecting the micro controller that resides inside that runs the sensors.

Main Mast Build:

Most of the mast is made from 1″ PVC with different connectors and such.  There are a few places in which the 1″ is not used, for example, where the micro controller resides.  (You can see it as the larger section). It uses 3/4″ PVC inside 1.5″ PVC.  It is built this way to provide some waterproofing for the micro controller.  The other section is for the temperature & humidity sensors.  It uses some 2″ PVC as a sun shield for the sensors.  As for the wiring of the sensors, I will detail that a little later, but all the wiring for the sensors comes together at a point where the larger section starts.  It’s there where I  “harness” everything together and will detail that later.


As I said, there are 5 sensors within the mast.  3 are sensors I have built myself and two are not.  For the sensors I have built myself, I have linked to the posts in which I detail how to build them.

  1. Wind Vane – Link to post
  2. Anemometer – Link to post
  3. Rain Gauge – Link to post
  4. Temp Sensor – Link to post
  5. Humidity Sensor – Link to post

Microcontroller & Wiring:

In previous versions of the mast, I have used an Adafruit Trinket board, but when I attempted to add some additional sensors (which failed miserably due to waterproofing) it didn’t have the needed pins required, so I switched to a Arduino Pro Mini 3V.  The Pro Mini is slightly larger, more powerful and allows me to power it with 5V coming from the Raspberry Pi.

As I said before, I communicate with the Pro Mini from the RPi via I2C.  To do this, I have a cat 5 cable running from the enclosure to the Pro Mini (I only need 4 of the wires, but it’s nice to have a spare 4 in case something happens) and then another piece of cat 5 that runs from the Pro Mini to the wiring harness.  I’ll make another post regarding the wiring for the micro controller and the wiring harness as I believe this one has gotten a little long. Link to post

Stay tuned for more…

Updated Weather Station

Working on updating my weather station currently. It’s been out of commission for a year or so. The rubbermaid box I had it in didn’t last in the elements so I’m having to rethink my mounting process. I’m also looking into getting a larger battery because the 6000 maH one I’m using doesn’t last that long.

I’m also going to be improving it. I’ve put together a circuit to measure how much battery I have left so I can have it turn itself off when the battery is too low. Also have a few more calculations that I can add in to my reporting like heat index which will be useful for the summer.

Gemma Neopixel Jewel Earrings

I like projects! I NEED projects!

I’ve wanted to do something in the wearables category for a while, but couldn’t think of something. I was out at the mall one evening with my beautiful wife looking through some of the department stores. I decided to call my sister-in-law (for a reason I can’t remember right now) and the idea popped into my head that I should make her some of the neopixel earrings I’ve seen in the Adafruit Learning System. So I told her I was going to make them and when I got home I went onto Adafruit’s site to purchase what I would need.

The original plans for the earrings include neopixel rings, but I noticed that they had just released a new neopixel “platform” called the “Jewel”. This has 7 neopixels arranged in a circle with 1 more in the middle. I thought these would be more fun to have than the rings, so they were added instead. The only other parts you need are a tiny lipo battery and of course an Adafruit Gemma. (Don’t forget the charger for the batteries as well if you don’t have one)

I feel bad that I didn’t take pictures of the entire process, but it’s really, really simple. The first thing I did was shorten the battery leads. There’s no need for all that length of wire. After that, I wired the Jewel to the Gemma with silicon wire with enough room to slide the battery between the 2. (They are back to back.) 3vo on the Gemma to +5V on the Jewel, Ground to Ground & D0 on the Gemma to input on the Jewel.

To keep them together, I did a no-no and used hot glue. You slide the battery in position and make sure it all will align well (I aligned one of the mounting holes on the Jewel to D1 on the Gemma). Slightly lift the battery on one side so you have room to place the hot glue on the back side of the Gemma, then press the battery down into place. Repeat the same process with the Jewel on the battery making sure it’s aligned.

For the code, I took what was given on the Adafruit tutorial for the ring earrings and modified it to only sparkle and to sparkle specifically in teal (my sister-in-law’s favorite color).

// Low power NeoPixel earrings example. Makes a nice blinky display
// with just a few LEDs on at any time…uses MUCH less juice than
// rainbow display!


#define PIN 0

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(7, PIN);

uint8_t mode = 0, // Current animation effect
offset = 0; // Position of spinny eyes
uint32_t color = 0xffae00; // Start red
uint32_t prevTime;

void setup() {
pixels.setBrightness(60); // 1/3 brightness
prevTime = millis();

void loop() {
uint8_t i;
uint32_t t;

switch(mode) {

case 0: // Random sparks – just one LED on at a time!
i = random(7);
pixels.setPixelColor(i, pixels.Color(0,128,128));;
pixels.setPixelColor(i, 0);



Add some earring pieces from Walmart and they should sparkle like these:

Youtube Video

I2C sensors using Adafruit Trinket

I finally completed migrating the weather sensors for the weather station that is at my father-in-law’s farm. I had issues with the rain gauge not working too well with the pi directly, so I decided to use an Adafruit Trinket to capture the values of the sensors and send them to the pi for tracking. The communication between the two is accomplished using I2C.


Here’s the completed mast with sensors attached. (This is actually a pic of it at my house for testing) What you’ll need for this is 1 of each of an anemometer, wind vane & rain gauge. It works with the sensors I built, but I’m sure you could incorporate it to use any sensors you have as well.

I’ve used PVC to build all my sensors as it’s easy to connect together. In my anemometer & wind vane posts I have used certain PVC pieces to allow for connection to my mast. For the rain gauge, it’s a little different. I used a piece of cedar fence board to secure the sensor, then some u-bolts to attach the board to a 1 inch pvc pipe, plugged one end and drilled a hole for the wire to run through.

For the rest of the top part of the mast I use a 1″ T-connector at the top with about 8 or so inches of 1″ pipe to connect the anemometer & wind vane. I run the wires down through the pipes. I then use a small piece of 1 inch pipe (about 3 or so inches) to connect another T-connector for the anemometer. I then use another portion of 3 or so inches of 1″ pvc pipe to connect to the lower portion. (Sorry, but I don’t have any pics of this…)

The lower mast is where the trinket comes in…I connect all the sensor wires to a single cat 5 cable to connect to trinket and then another wire for the I2C communication. The idea is to house the trinket in some 3/4″ pipe that is waterproofed and have it sit inside some 1 1/2″ pipe. (You can see this bulge in the pic above) I use some connectors to move from 1″ to 1 1/2″ pipe. Then a portion of 1 1/2″ pipe (I think it’s 12 inches long) and then connect it back to another 1″ piece of pipe to mount it.

Before wiring up your trinket, make sure you upload the code to it. Here is what I use which tracks the sensors and sends the data via I2C:

#include avr/interrupt.h
#include TinyWireS.h

// setup cbi & sbi for interrupts
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

//Define address of device
#define I2C_SLAVE_ADDRESS 0x04

// Set up registers to hold data to send
volatile uint8_t reg[] =


// Set up variables used

volatile byte reg_position; // keep track of reg position sent from master
volatile int rainGauge = 0; // keep track of interrupts from rain gauge
volatile int windSpeed = 0; // keep track of interrupts from anemometer
volatile int windDirection = 0; // keep track of value of wind direction sensor
volatile int windSpeedSend = 0; // used to send 10 second interrupt value to pi
long debouncing_time_rain = 300; //Debouncing Time in Milliseconds for rain gauge
volatile unsigned long last_micros_rain; // micros since last rain gauge interrput
long debouncing_time_wind = 100; //Debouncing Time in Milliseconds for anemometer
volatile unsigned long last_micros_wind; // micros since last anemometer interrupt
volatile int val1 = 0; // pin 1 value at interrupt
volatile int val2 = 0; // pin 4 value at interrupt

// Function to send data when it is requested. Sends 2 register positions
// for each request
void onRequest()

// Load all values into registers. (even though only 2 will go to master)
reg[0] = lowByte(windDirection);
reg[1] = highByte(windDirection);
reg[2] = lowByte(windSpeedSend);
reg[3] = highByte(windSpeedSend);
reg[4] = lowByte(rainGauge);
reg[5] = highByte(rainGauge);

// send 2 reg positions to master

// Function to set which register positions you wish to receive
void receiveEvent(uint8_t howMany)
reg_position = TinyWireS.receive();

// if requested position is 7, reset rain gauge variable. Will be sent at midnight each day
if(reg_position == 7) {
rainGauge = 0;


// Setup for connection
void setup()

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt. Turn on Pin 1
sbi(PCMSK,PCINT4); // Which pins are affected by the interrupt. Turn on Pin 2

void loop()

// anemometer counts interrupts for 10 second interval. This is sent to master for calculation
windSpeed = 0;
windSpeedSend = windSpeed;

// read pin 3 analog value of wind direction sensor
windDirection = analogRead(3);

// Check for connection to be stopped.

// debounce rain gauge. make sure new reading is greater than old reading + debounce rain micros
void debounceRainGauge() {
if((long)(micros() – last_micros_rain) >= debouncing_time_rain * 1000) {
last_micros_rain = micros();

// debounce anemometer. make sure new reading is greater than old reading + debounce wind micros
void debounceWindSpeed() {
if((long)(micros() – last_micros_wind) >= debouncing_time_wind * 1000) {
last_micros_wind = micros();

// function to increment rain gauge count
void rainGaugeFunc() {
rainGauge = rainGauge + 1;
} // end of rainGauge

// function to increment anemometer count
void windSpeedFunc() {
windSpeed = windSpeed + 1;
} // end of rainGauge

// interrupt service routine. What to do when an interrupt occurs as all pin change interrupts
// on ATTiny85 trigger PCINT0 vector.
ISR(PCINT0_vect) {
// get value of pin 1 @ interrupt
val1 = digitalRead(1);
// get value of pin 4 @ interrupt
val2 = digitalRead(4);

// if pin 1 is HIGH (caused the interrupt), proceed with rain gauge increment functions
if (val1 == HIGH) {

// if pin 4 is HIGH (caused the interrupt), proceed with wind speed (anemomether) increment function
if (val2 == HIGH) {


So, now to the wiring:

Here is the wiring diagram I drew out that shows how everything is connected. When connecting, make sure you use solder and shrink tube to protect the joints.


After all the wires are connected, drill a hole in a 3/4″ pvc plug and push the wire through that hole prior to connecting to the trinket. You may want to run it through a piece of 3/4″ pipe as well (about 8 or so inches).

All 3 sensors will need 1 wire connected to the +3v on the sensor. I managed to get all 3 of the cat 5 wires into the hole on the trinket. The read wires will need to go different pins. For the anemometer and rain gauge, you will need to connect a 10k resistor to ground to pull the pin to ground. The rain gauge read wire should go to pin 1 and the read side of the anemometer should go to pin 4. The read wire for the wind vane should go to pin 3. Connecting all the ground wires was fun. What I did was run 1 wire out of the trinket and connected all the ground wires to it and put shrink tube over all of them. (You can see it in the pics below.)



I didn’t take a lot of single step pics on this and I apologize. You can see the connections for the I2C wire as well in these pics. The last part is connecting the wires for the I2C communications. You’ll want to put the wire through hole in another 3/4″ pvc plug before you connect them to the trinket to allow for waterproofing. Connect the +v to the battery pin (I use 5 volts out of my raspberry pi to power, but you can power it any way you want. I used a 3 volt trinket for this setup). Ground to your ground wire, SDA to pin 0 and SCL to pin 2. Once this is done, slide it all into the 3/4″ pvc and plug the other side. It should look like this:


Place some hot glue on each plug where the wires go in to keep the water out, then shove this into the 1 1/2″ pvc pipe and then connect the rest of your mast.

This is really set up to communicate with a pi, but I’m pretty sure it would work with an Arduino as well. In the code you basically send the trinket a number and it will give you the response. Sending 0 will give you the wind direction reading, 2 will give you the wind speed reading and 4 will give you the rain gauge reading. Sending it 7 will cause the rain gauge count to reset. Here’s a quick bit of code you can use for the pi:

# Import needed libraries
import smbus
import time

# Set I2C address of device you wish to access
DEV_ADDR = 0x04

bus = smbus.SMBus(1)

# Request values from device. Number is start register position.
while True:
print 'Testing for connection...'
while True:
wind_dir_read = bus1.read_word_data(DEV_ADDR, 0)
wind_count = bus1.read_word_data(DEV_ADDR, 2)
rain_count = bus1.read_word_data(DEV_ADDR, 4)
except IOError:
print 'No connection...'
if wind_dir_read < 1030: break else: print 'Value too high.' time.sleep(5) # Use this to reset a variable: #d_val = bus.read_word_data(DEV_ADDR, 7)

It doesn't seem that wordpress knows how to deal with indents in it's code sections, so make sure you indent it properly. Sometimes the trinket can give you some funny business which I've handled via the error trapping above. If you keep this bit of code you shouldn't run into any problems.

Wind Direction Reading

As I stated in the previous post, the readings of this sensor take a lot of work to setup. You have to get a reading at each direction and then split the difference between them to get a high and low. Somewhere I have an excel file that I use to do all the calculations and print out the code. I’ll load it here if/when I find it.

To use this, you will need to place an include in your python program:

from wind_dir import wind_dir

Then when you want to get the value, you call the function with your ADC reading:

wind_direction = wind_dir(wind_dir_read)

The annoying part of this is setting up this file. All it does is take your reading and see where it falls within the table of max & min values established through testing:

#!/usr/bin/env python


def wind_dir(amt):
if amt <= wind_dir_high_NNE and amt >= wind_dir_low_NNE:
wind_direction = 'NNE'
elif amt <= wind_dir_high_NE and amt >= wind_dir_low_NE:
wind_direction = 'NE'
elif amt <= wind_dir_high_ENE and amt >= wind_dir_low_ENE:
wind_direction = 'ENE'
elif amt <= wind_dir_high_E and amt >= wind_dir_low_E:
wind_direction = 'E'
elif amt <= wind_dir_high_ESE and amt >= wind_dir_low_ESE:
wind_direction = 'ESE'
elif amt <= wind_dir_high_SE and amt >= wind_dir_low_SE:
wind_direction = 'SE'
elif amt <= wind_dir_high_SSE and amt >= wind_dir_low_SSE:
wind_direction = 'SSE'
elif amt <= wind_dir_high_S and amt >= wind_dir_low_S:
wind_direction = 'S'
elif amt <= wind_dir_high_SSW and amt >= wind_dir_low_SSW:
wind_direction = 'SSW'
elif amt <= wind_dir_high_SW and amt >= wind_dir_low_SW:
wind_direction = 'SW'
elif amt <= wind_dir_high_WSW and amt >= wind_dir_low_WSW:
wind_direction = 'WSW'
elif amt <= wind_dir_high_W and amt >= wind_dir_low_W:
wind_direction = 'W'
elif amt <= wind_dir_high_WNW and amt >= wind_dir_low_WNW:
wind_direction = 'WNW'
elif amt <= wind_dir_high_NW and amt >= wind_dir_low_NW:
wind_direction = 'NW'
elif amt <= wind_dir_high_NNW and amt >= wind_dir_low_NNW:
wind_direction = 'NNW'
wind_direction = 'N'

return wind_direction

As you can see from the above, I get all the way down to the minor directions such as “NNE” & “ESE”, etc. You can change it to suit your needs.

Wind Direction Sensor

This is one of the easiest sensors I’ve built. Basically it is a 10k 360 degree potentiometer with a wind vane attached to the top. I set North equal to 0 resistance and then record the values through testing at the other directions and then split the difference between them. (Will explain this more when I do the coding part)



Here are the two main parts to the sensor. A Bourns 6639S-1-103 10k rotary potentiometer and a Davis instruments wind vane with brass tip for Vantage Pro2 anemometer. You’ll also need some cat3 or cat 5 cable, a 1 1/4″ to 1″ PVC “T” and two 1 1/4″ PVC plug.


First you want to drill a hole in the middle of the PVC plug for the pot to go through. (Make sure you can get all the threads through the hole).


Before you tighten the pot into the hole, you’ll need to solder some wires to the bottom of the pot. For the Raspberry Pi, you only need one on peg 1 and one on peg 2 (Power on peg 1 & read on peg 2). For Arduino, You’ll need to attach a ground to peg 3 of the pot. Make sure and use some shrink wrap to protect the joints.


Once your soldering is done, tighten down the pot into the hole and slip your wire through the “T”. Make sure you mark “N” on your plug where 0 resistance is read after the pot is tightened down. Keep your pot adjusted to this position. Slide the plug into the T. (Place another 1 1/4″ plug in the other side).


Finally, you’ll need to attach the vane. The vane has a small Allen screw in it. You’ll need to loosen it up before you slide the vain onto the post of the pot. Adjust the vane so it’s just barely off the plug, point it towards “N” that you marked on the plug and tighten it down.

As far as wiring this sensor, the wire soldered to peg 1 should go to +v, the wire soldered to peg 2 should go to either an read spot on your ADC (if you’re using a Pi, something like the MCP3008) or to an analog read pin on your Arduino, and the wire on peg 3 should go to ground (if it’s connected)

I’ll share the reading code part later when I can get on my main computer at home.

Anemometer Reading

It was too late last night when I finished the post about building the anemometer that I didn’t want to get into the code to read the wind speed. As I said before, basically what I do is I count the number of “triggers” within a 10 second period and then feed that into the formula that came from testing it with our car.

Here is the code I use for Raspberry Pi…I run this every 5 minutes (with the rest of my measurements) to get the wind speed at that time.

# calculate windspeed
# set up the GPIO to be an input and activate the internal resistor to pull down the pin to low
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# This is the interrupt function. It opens a file, pulls the number from the file and adds one to it, then rewrites it to the file.
def wind_callback(channel):
windfile = open("/home/pi/wind_count.txt")
windtext = windfile.readline()

wind_count = int(windtext)
wind_count += 1
windfile = open("/home/pi/wind_count.txt", "w")


# Here is the interrupt setup. We are setting it up on pin 22, looking for it to rise, calling the function "wind_callback" when it is triggered and
# debouncing it by 100ms
GPIO.add_event_detect(22, GPIO.RISING, callback=wind_callback, bouncetime=100)
# Before we start the count, we open the file and set the number to 0
windfile_clear = open("/home/pi/wind_count.txt", "w")
wind_count_clear = 0

# now we sleep for 10 seconds to get the readings

# After sleeping, we open the file and read the number
wind_file = open("/home/pi/wind_count.txt")
wind_count = wind_file.readline()

# in order to use it in some math, we need to convert it to an int
wind_count_comp = int(wind_count)

# here is the formula created from testing. Basically it is .0023427x^2 + .46244x
windspeed_a = wind_count_comp * wind_count_comp * .0023427
windspeed_b = wind_count_comp * .46244
windspeed = windspeed_a + windspeed_b

# round it off to 1 decimal.
windspeed = round(windspeed, 1)

I am actually in the middle of a redesign on my weather station due to the Raspberry Pi not being the best at interrupts for the rain gauge. For the one at my father-in-laws farm, I will be using an Adafruit trinket to capture all the data from the anemometer, rain gauge, and wind direction sensor before relaying it to the Pi. This type of sensing is better for a micro controller than it is for a Linux computer such as the Pi. For my home weather station, I’ll be using a Arduino Pro Mini as I have a lot more sensors on my mast. The Trinket code is a little more difficult due to the ATTiny85 that runs it. I’ll post info on how to connect it to a Raspberry Pi later.

Here is the code for the same principal as above on a trinket. The big difference here is that this runs constantly. Every 10 seconds I have a wind speed reading, although I only pull it every 5 minutes.

#include avr/interrupt.h

// setup cbi & sbi for interrupts
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

// Set up variables used
volatile int windSpeed = 0; // keep track of interrupts from anemometer
volatile int windSpeedSend = 0; // used to send 10 second interrupt value to pi
long debouncing_time_wind = 100; //Debouncing Time in Milliseconds for anemometer
volatile unsigned long last_micros_wind; // micros since last anemometer interrupt
volatile int val2 = 0; // pin 4 value at interrupt

void setup()
// Setup Pins for interrupts

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
sbi(PCMSK,PCINT4); // Which pins are affected by the interrupt. Turn on Pin 2


void loop()

// anemometer counts interrupts for 10 second interval. This is sent to master for calculation
windSpeed = 0;
windSpeedSend = windSpeed;


// debounce anemometer. make sure new reading is greater than old reading + debounce wind micros
void debounceWindSpeed() {
if((long)(micros() - last_micros_wind) >= debouncing_time_wind * 1000) {
last_micros_wind = micros();

// function to increment anemometer count
void windSpeedFunc() {
windSpeed = windSpeed + 1;

// interrupt service routine. What to do when an interrupt occurs as all pin change interrupts
// on ATTiny85 trigger PCINT0 vector.
ISR(PCINT0_vect) {
// get value of pin 4 @ interrupt
val2 = digitalRead(4);

// if pin 4 is HIGH (caused the interrupt), proceed with wind speed (anemomether) increment function
if (val2 == HIGH) {



I’ve been meaning to do this for a long time…so without further delay, here is my DIY anemometer.

For those not familiar with what an anemometer is, they are used to measure wind speed. There are certain drawbacks to my design, but after having it active for at least 6 months. I think it works fairly well. The way it works is that it has a reed switch that is triggered with a magnet. In my program, I have it hooked up to an interrupt and count the number of times it triggers within 10 seconds and then plug that into a formula. To come up with this formula, I created a setup on an Arduino that constantly looped the 10 second count. My wife and I took the car out to a county road and did some tests at different speeds. I took the average of 3 tries at 5 different speeds to create the formula I use to convert trigger count to mph.

What you’ll need:


A 7/16″ threaded rod with some nuts and a washer, a 3/4″ to 1″ PVC “T”, a 1 1/2″ PVC cap, a 1″ cap (I think this is the size that fits over one of the sides of the “T”), a slip bushing that will fit in one of the 3/4″ sides of the “T” (that the next item will also fit in), a bearing, 3 ladle spoons (cheap @ Walmart), some small bolts and nuts (I’ll place the size in later), a very small magnet, a reed switch, and some cat 3 (or cat 5) cable.


The first step is a bit of work. You have to get the bearing inside the bushing and have it flat with the bushing. What you’ll need to do is sand out the bushing some and use a piece of wood and a clamp to squeeze it in. It’s very important that it is as straight as possible.


Next we begin to make the shaft. Place a lock nut at one end of your 7/16″ threaded rod.


Now place the rod through the bearing so that the lock nut is inside the bushing. On the other end of the threaded bushing, you’ll need two nuts. The first nut will need to hold the rod against the bearing, but not so tight that the rod will not spin. The second nut is to make sure that the first nut doesn’t move. (Work the first nut down to a list past the tightness to the bearing you need, then put the second nut on. Tighten the second nut while loosening the first to get it good and locked.)


Now comes another difficult part. You’ll need to put a hole for the rod in the exact middle of the 1 1/2″ PVC cap. I think I went through 5 caps before I got it right. (A drill press is your friend). You also need to place two holes in each of the ladles so that your small screws will fit. (These are stainless steel, so go slow! It’s fairly difficult to drill through it) Make sure they are in the center of the handle and that you have the center line marked the same for each spoon. The other piece of this step, you’ll need to bend the handles of the ladles so that they are perpendicular to the ladle. (The come kind of curvy)



Showing the center lines and the bent handles.


To attach the ladles to the PVC cap, you’ll need to mark and drill 3 holes. They need to be 2 7/16″ from each other and 1″ from the bottom of the cap. (Using a soft sewing tape measure works well for this.


Now here’s where the center line comes in handy. You’ll need to bend the handles of the ladles on this center line as shown.


Now attach the first ladle to the cap and get it level with a table. Mark and drill the hole for the other screw and attach the other side of the ladle to the cap. Continue to do this for the other two ladles. (I used lock nuts to attach these screws.


Hot glue your magnet (or 3) inside the cap.


Now for some of the electronics. Take your reed switch and bend one side like shown. Be VERY CAREFUL, these are delicate.


Now solder a wire to each side as shown and place shrink tube over the joints. I have found that you will need water proof this a bit. There are two ways to accomplish this…carefully place shrink tube over the reed switch and seal up the top, or buy these from Sparkfun.


In this step you’ll need to cut your threaded rod to size. Place two nuts (use the locking feature explained earlier) and a washer on the rod and place the cap on. Adjust the nuts so that the magnet would pass over the reed switch when shown attached above. Give yourself enough room on top side of the cap to place two more nuts on and cut the rod with a hacksaw. Be careful not to mess up the threads. (Too much). Next use hot glue to attach the reed switch and wire as shown. Almost Done!



Finishing up, drill a hole in the side of the “T” so the wire can go back inside. Hot glue around the wire to keep it still. You can use 1″ PVC to connect it to the other parts of the weather station. (as shown in the following picture..) Place the cap on the underside of the “T” to keep things out. Here is a finished version on the desk and attached to the “mast”. I will post the python (and now Trinket as I’ll go into later) code that use later.