This page covers the design of a unit to monitor an anemometer (wind speed sensor) and also a wind vane (for wind direction). It has a simple serial interface so can be easily added to microcontroller projects, such as weather stations and dataloggers.
The problem: How to accurately and reliably monitor an anemometer and a wind vane?
Any logging device must constantly measure pulses from the anemometer and keep track of the wind direction. But dedicating time and effort from a microcontroller processor consumes power and energy and also requires accurate timing. Ideally we want to move the constant monitoring function to another device and then just interrogate this from our main logging unit whenever we can. Here is an overview of what this unit does:
I’ve done quite a bit of discussion and work on a DIY wind data logger. I’m not going to cover anemometers in great detail apart from highlighting there are four main types:
- Pulse output
- Typically have a magnet reed switch which gives a switched pulse output
- Usually 2-wire
- Hall Effect output
- Has a hall effect sensor which detects a spinning magnet
- Output is a wobbly sine wave with varying amplitude (fast = high amplitude, slow = low amplitude)
- Usually 3-wire, requiring power
- Need to convert the sine wave into pulses
- NPN transistor output
- Very similar to the Pulse output, but using an NPN transistor which pulls the signal down
- Typically 3-wire
- Voltage output
- Output voltage is proportional to the wind speed
- Usually a small motor run as a generator
- Very low output at low wind speeds
- Can be 2 or 3 wire
So I wanted to create a design which can monitor all of these types (if possible), but certainly the pulsed output and hall-effect types. This needs to convert the anemometer signal into a nice digital pulse or analogue value. The unit will also measure all the pulses and keep track of the actual wind speed over different timescales. It can then service serial requests for this data. I wanted to store 10s, 1min, 10min averages along with minimum and maximum values from within the sample period (this helps to show how turbulent the wind is). Other clever statistical analysis could be done, although I’m not clever enough to do that!
I obtained three different samples for testing. I needed to know their ‘transfer function’ which is the conversion between pulses or output from the device and the real wind speed (in m/s or mph). These were:
- Vector Instruments NRG #40C.
- This is a very good quality hall-effect unit.
- This has a transfer function of Scale Factor (Slope): 0.765 m/s/Hz (1.711 mph/Hz) with an Offset: 0.35 m/s (0.78 mph)
- A low cost pulse output (reed switch) from Maplin electronics (when it existed!)
- This was a spare part for a low cost weather monitoring station they sold.
- These are still available on eBay and Aliexpress.
- This is a plastic unit and I have heard about these breaking in high winds.
- The transfer function is not fully known, but from my previous tests I found that a conversion factor of 0.7m/s per Hz gives a reasonable output (but this needs testing further!)
- A medium cost NPN transistor output unit from AliExpress
- Part number: PR-3000-FS-NPN
- This is a metal construction unit, so hopefully quite robust.
- The pin out is in Chinese, but the manufacturer let me know:
- V+ is BROWN, V- is BLACK and OUT is GREEN. (At least I think so!)
Wind Speed Measurements
There is an international standard for measuring wind speeds, which I wanted this converter to coply with. The standard is IEC 61400-12-1:2017 (paid for copy) or some infroamton relating to this is available on Wikipedia.
In the end I designed a unit to record the average wind speed for 1 second, 10 second, 1 min, 10 min and 1 hour averages. This data can be requested from the unit at any time. Typically the 10 min average is the most suitable for use here.
Wind Speed Conversion Circuit
The output from the anemometer is either a switch, an NPN transistor or a very small AC output (hall-effect units). I wanted my circuit to work with all three of these (it does not work with voltage output units). I designed a very simple op-amp comparison circuit with a pull up on the input. This compares with a very small voltage (around 0.3V if powered from a 3.3V supply). So the pulse output will pull the signal low, creating a pulse on the output of the op-amp. The hall effect will create a small voltage signal which will cause the output to rise to the output voltage, again creating a pulse. There is no filtering on this circuit, as I perform all the de-bouncing within the firmware (so it can be adjusted as needed).
Wind Speed Conversion Values
We want to convert the number of pulses from the anemometer into a wind speed. This will depend upon the type of anemometer and it’s calibrated conversion factor. This will be different for different manufacturers and types of anemometer, so you need to get this information from your supplier.
This unit uses a y=mx+c linear conversion of the pulses to wind speed, so the output wind speed = m x number of pulses + c. If the pulses are zero then the unit outputs a zero (so the +c factor is ignored). Negative values are also ignored if calculated. The conversion values for m and c are stored in EEPROM and can be changed with serial commands.
You can set the m and c values to give output in m/s or mph, this depends upon the data you would like. You can just see the average pulses by setting m= 1 and c = 0, so the output is the number of pulses.
We also store the minimum and maximum values for the wind speed within and averaging period. This is useful to see the turbulence within the data.
Wind Direction Measurements
The output from the wind vane is usually a variable resistance. If a voltage is applied to each side of the variable resistor then the ‘wiper’ on the resistor will give an output voltage that is proportional to the vane direction.
I only had one unit to test here, but I hope to obtain more for adding to this list and creating code for. I have designed the firmware so that the type of wind vane can be trained for your sensor board. This means we can train it for any resistive wind vane and also re-calibrate for ones aligned incorrectly.
The circuit used here is a voltage following op-amp circuit. So the voltage read on the analog pin will be the voltage from the vane. This buffers the input impedance, which hopfully helps with the reading accuracy, but should not do much else.
The main problem here is to record the value in the most sensible way. If a wind vane with a resistive output is used and (say) the North direction is the point at which the resitance resets (goes from full resistance to zero resistance) then what would we see as an output voltage? So it the vane is just west of N then we will see the foll voltage (1024 reading on the ADC), if the vane is just east of N then we will see close to 0 V and hence 0 reading from the ADC. If we were to just average these values then we will get (1024 + 0) / 2, which is a reading 512, which is the same as South! So we would not see the correct data if we just average the values.
Another solution to this (which I have used before) is to firstly set bands within which a N,S,E etc reading is stored and then ‘bin’ the data and then record the direction with the highest number of samples within it. This means we need to create an array of directions and record the data into that.
In order to investigate the spread of values (which shows turbulence in the wind speed) then we have the issue where we could get the following data:
- Direction: N NE E SE S SW W NW
- Data: 0 0 0 0 9 0 0 0 : Very direct
- Data: 1 1 1 1 2 1 1 1 : Not direct – turbulent?
- Data: 0 0 0 3 6 0 0 0 : Quite direct
For all of these then the main direction is South. But one is always South, One is from most directions and one is S to SW. So how can we deal with this variation? All the samples add up to 9.
The solution I came up with was to record the number of seconds that the vane is within each direction band. This is within 0.1 seconds, which is the time between each check of the vane direction. When we ask the unit for the wind vane data then the device will return the instantaneous wind direction. It will also return an array of data giving the number of seconds that the wind vane has been in each direction, within 8 sections. This allows us to create a wind rose for the wind speed data. The wind direction data can be reset at any time, allowing different averages to be achieved.
Wind Vane Training
One issue with using different wind vanes with this unit is that they are all different. Some have a reisitive output that varies from 0 ohms is (say) North and the wiper for the resistive unit gives the different directions. Some lower cost unit have reed switches which connect in different resistors and these are not linear, so, for example, N= 10k, S = 52k E = 5k etc. These could be any values at all and totally depends upon the vane manufacturer.
To get around the different wind vanes available then I have included a ‘training’ mode where we let the unit know what values to expect. We enter the vane training mde with a serial command (see github repository). The unit will then let you know what direction to point the vane. Point the vane in the correct direction and press the user switch. This will move to the next direction. This goes N-NE-E-SE-S-SW-W-NW then ends. The data is stored into EEPROM and ‘bands’ around the values are created so that if the value is within a band it will respond with that direction.
The bands go from the midpoint below the value up to the midpoint above the value. So, for example, if the unit has recorded S as a value of 600 and SE as a value of 500 and SW as a value of 750, then the band for south will be from 550 to 675. This also deals with ‘wrap around’ from highest value (1024) to lowest value (0). For example if NW is 900, N is 0 and NE is 200, then the band for N is from 962 up to 1024, then also from 0 to 100. Check the code for more details, as this was quite complex to calculate!!
To ensure this is kept up to date, I only want to record this information in one place!
Please see the serial commands within the readme of the github repository: https://github.com/curiouselectric/WindSensor
A small PCB was designed using KiCAD, measuring just 50x50mm. It is a surface mount component unit to keep the size of it small. It is based upon the ATMega328 microcontroller, which is used in the Arduino. I wanted the unit to work at 3.3V, so I needed to reduce the processor clock down to 8MHz in order to keep within the correct IC speed. This meant I could not use the Arduino bootloader (which expects a 16MHz clock). I use the MiniCore project which supports different clock frequencies. I used an Arduino as an ISP to initially program the units with the bootloader. After that I could use a simple USB to serial converter to upload new code.
Code was written in C++ and uploaded via the Arduino IDE. It is all open source and available in the repository below.
Project Code and Design Repository
All the PCB design and firmware is held in the github repository here:
Updates will be applied to that github account to keep track of serial commands etc, so please check out the github for the most up to date information on this project!