Analogue Wind Vane With Auto Set Up

Introduction: Analogue Wind Vane With Auto Set Up

As the amazing online GPRS Weather Station project continues, we have yet another upgrade to the vast array of sensors with a professional analogue wind vane, kindly donated by Vector Instruments. This device will eventually be hooked into the new, upgraded, weather station module that I am designing. The current prototype is producing live data here: http://www.goatindustries.co.uk/weather/ .

Comparing this sensor to my DIY Digital Wind Vane the first thing I noticed was the extreme sensitivity to wind movement - it has very low torque - so it is able to pick up wind direction even in very small wind speeds. Secondly, being made on a CNC lathe, the quality of the engineering is superb - I really must get myself a CNC lathe!

Here, I am going to show how I set up and coded an arduino to read the sensor, made calculations for non-linearity, took account of the 'dead zone' in the potentiometer, turned the readings into a large numerical array, efficiently calculated the mode value and made the whole device set itself up automatically. No pressure!

Step 1: How It Works

This analogue wind vane is based on a very expensive potentiometer with three main connections - 5V, ground and wiper. The wiring inside the deice is very thin so great care is needed not to put too much current through the circuits for too long or it could quite easily get burnt out.

I have protected the wiper part of the circuit with a 10k resistor which feeds a signal to the arduino via pin A0. This is then converted into a digital 10 bit code inside the processor with a full range of 0 to 1024. The device is never fed a continuous supply of power and is pulsed in two different ways. Firstly, there is a load of really fast 50 millisecond pulses which gets us 10 readings at a time, next the whole device goes off for 1/2 a second until the next batch of readings is made. By working out an average (mean), we end up with one fairly accurate reading per second.

So now that we've got this digital reading - what else could be simpler? Surely that's the end of it?

Step 2: Project Challenges and Solutions

Firstly, when working with analogue to digital conversion in the past, I have noticed significant 'drift' around minimum and maximum values and so some code is going to need to be written to counteract this phenomenon. Secondly, wind can sometimes be extremely turbulent which makes it very difficult to get an accurate output value. If the wind was constantly changing from, say, south to west we would want to process our data in such a way that it would give the most common direction, not just the average or 'mean', otherwise we would just get a value of south-west. To explain in more detail - the wind might veer from south to west and back again, but actually it's mostly coming from the south-south-west. If this is beginning to hurt your brain cells, I totally sympathise!

Fortunately we have solutions to both the above problems - we take as many readings as the system memory and speed will allow and build some truly massive arrays of numbers. We then make a continuous log of the number of times each part of the array is hit and then, finally, spit out the most popular. In the digital wind vane project I wrote some rather clunky code for calculating the 'mode' value and now, with the power of some extra nutritious coffee granules, I have reduced that code to something rather more sublime!

Finally, after about ten minutes, just when our arrays are about to explode the arduino into a million fragments of silicon dust, we retrieve a single wind direction value eg 215 with a second arduino and reset all the large numbers to zero.

Now that we're beginning to feel quite glib about our engineering prowess, the analogue wind vane chucks at us 2 more major problems - ONE: With the recommended 100K load in place, it does not produce a true linear output and TWO: it has a dead zone around the north pole of about 3 degrees. At first, my brain cells started to panic at the prospects of solving the non linearity problem but then they remembered that wind is always slightly turbulent so the question arose: How accurate do we really need to be? Do we really need to look into a lot of detail at the non linearity curve? Common sense then came to the rescue and the curve got chopped and straightened into 2 simple straight lines, with an apex at 240 degrees. Simple!

Step 4: Arduino Setup

This is the easy and fun part and we can make lots of reassuring beeping noises and flickering of LEDs to make us feel better after having brutalised our brain cells so much in the previous steps. The LED flickers because the power supply is being pulsed and the micro speaker beeps when we have got the wind vane in the self calibration zone.

After wiring up the breadboard, we connect the power and point the wind vane to due north, which will be in the dead zone. We then move the vane very slightly to the left and right and there should be beeping noises produced in two separate audio frequencies, representing minimum and maximum range settings being discovered. Do this a couple of times and the sensor is set up and ready for use until the power is disconnected again.

As time goes on, but only when the wind is blowing roughly from the north, the maximum calibration setting is very slowly decreased, or pulled back, until it is over-ridden by a new setting. The same happens with the minimum setting, but in the opposite direction, i.e. pushed forwards.

I did also play about with the capacitor on the wiper pin and found that a 100 nano farad capacitor worked better than the 10 nano farad proscribed in the data sheets in terms of the stability of the end point values. This will, however, affect the sensitivity of the device as it sweeps backwards and forwards over the dead band.

Step 6: Upgrade to 15 Bit ADC and Code Improvements

After getting some feed back from technical support at Vector Instruments on this instructable, I made a few small changes to the test rig. They noticed that the 10K resistor that I was previously using to protect the wiper circuit was proberly too big for the nano ADC capacitance infrastructure and so this was reduced to 8.25K and kept in place for the upgrade.

The ADC was upgraded from 10 bit to 15 bit with an ADS1115 to give a much improved range. This was particularly useful when looking at the problem with minimum and maximum values by observing how they fluctuated using the serial monitor.

Another thing that technical support pointed me towards was that unless the coding was designed very carefully, we could get values of 180 degrees near the north point instead of 360. This is because we're taking a quick sample batch of 10 or so readings and taking an average, which is fine as long as the sensor does not 'hover' around north and pick up both very small and very large readings in the same batch. The code for dealing with this is fairly simple, it divides all the readings into two groups - 'big' and 'small' - and ignores the 'small' readings if the number of 'big' readings is bigger. Easy!

In the end, the variability equated to about +- 0.5 degrees near the north point. Variability in the mid range e.g. 180 degrees was pretty much zero although there would be some compound errors introduced due to not knowing the ADC range too well.

Step 7: Load Resistor Non Linearity Calculations

Just to prove that math can actually be fun I'll tell you how I discovered the non linearity adjustment formula through diagrams.

Initially, I did not set out to discover the formula - I just wanted to visualise the non linearity created by the load resistor (also known as a 'pull down' resistor). I wanted to try and isolate the curve and plot it as a graph in Microsoft excel.

Firstly, I plotted the actual curve, which is the total resistance created by the combination of the wind vane and the load ... and I called it 'Total (RT)'. Initially, I was disappointed as I could not actually see any curve at all, so then I changed both the axes to log10. Hey presto! I can see a curve! (The blue curve on the left in the diagram above).

The total resistance is given by this formula:

RT = (Rw * R L ) / (Rw + RL)

where:

RT is the total resistance

RW is the wiper resistance

RL is the load resistance

OK, so far so good - not too complicated?

Next, I wanted to see how my new fancy curve looked side by side with a boring straight linear curve, just as if the results were not actually a curve at all, but a straight line. The formula for this is:

RLIN = (Rw * RTMAX)/ RWMAX

where:

RLIN is the hypothetical linear resistance (the 'imaginary' resistance)

RW is the wiper resistance

RTMAX is the maximum value of the total resistance

RWMAX is the maximum value of the wiper resistance

This is all well and good, but where are we going to get the value of the total resistance from? I really though this was going to be easier than this, but then realised that we've already calculated this value above, it's just the maximum value of RT . But just for clarification, here is the formula:

Now we can plot our linear 'curve' (in red) and see if it's noticeably different from the curvy curve ..... and yes .... as long as we cheat by using log10, we can see the difference. If we open up the excel file, we can change the value of the load resistor to something stupidly small and get some pretty crazy curves produced.

Finally, I realised that we could then subtract the non linear curve from the linear curve and get a final outcome: the actual non linearity, or the 'difference' between the linear and non linear results. This is the pretty blus curve on the right and is given by:

RDIFF = RT - RLIN = (RW * RL) / (RW + RL) - (RW * RL) / (RWMAX + RL)

This equation could be reduced further, but the arduino nano is already going to struggle with some of the big numbers produced, so we need to help it along a little bit.

You'll see that the code is more 'clunky' than the formula and I've had to divide by 5 to reduce the size of some of the numbers. But it works!

Hopefully, I've now also proved not only that maths can be fun but also relevant to the real world! But what did all this work actually achieve?

If we remember from earlier on, the recommended minimum load resistor was 100K, but if we reduce these ohms we can make the readings significantly more stable near the dead zone. I tried lots of different permutations and, using the above formula to negate the non linearity, I ended up using a super accurate (+-0.1%) 30K resistor and still got good readings at due south.

Step 8: Final

This sensor is quite different from the digital wind vane that I built myself - it works approximately ten times better in very light winds and it's smaller and infinitely more robust. The dead zone is a bit of a pain in the proverbial, but after a bit of hard work, I did manage to get rid of all the 'spurious' readings that I got in the beginning. In some respects, the digital wind vane is better - it never needs setting up and there is no dead zone at north and it's much, much easier to code. There are, however, tiny dead zones between each individual 'bits' of data in the encoder that I used and there's so much torque needed to drive the rotary encoder that the vane has to be big and subsequently ugly. I did research other rotary encoders, but they all seem to have similar torque ratings.

There is an easy way to remove the dead zone from this sensor by doubling up on the potentiometer machinery - one pot piggy backed on the other and offset by 90 or 180 degrees - but this would double the torque required, make the device more expensive and infinitely more difficult to code. There's also another possible solution using 'spintronic Tunneling MagnetoResistance (TMR)' which sounds rather like something out of Lord of the Rings so, being a big fan of the hobbits etc. I simply MUST try this!

Although I love the thought of being able to build my own sensors, I have the greatest of respect for the provenance of this commercial one - it has been used in the most severe conditions for over 40 years, so will be replacing the DIY digital one at the earliest opportunity!

Comments

My Dad works for Vector Instruments (Windspeed) and was the guy who sorted out these instruments for you. I hooked up on the of Anemometers to a PIC micro ~4 years ago so feel free to give me a shout if I can be of any assistance (not that I think you'll need it!) :)

Great work. I too had contemplated with frustation on using several μ-controllers for the anemometer, rain gauge and the rest of them. This instructable had come at the right moment; and I had always "felt" the reported wind speed data was less that it should be.