Interfacing Wind Vane

Hello,

I am interfacing a wind vane and anemometer with the arduino.

http://www.sparkfun.com/commerce/product_info.php?products_id=8942

I currently have everything setup and working. The issue however is that the wind vane is giving sloppy readings. I have it setup to give an analog reading of 0-1024 based on its position. It works great except for the fact that it is giving lots of sporadic 72s and 0s. Any suggestions?

9 MPH,0
9 MPH,252
9 MPH,286
9 MPH,252
9 MPH,248
9 MPH,248
9 MPH,72
9 MPH,0
9 MPH,72
9 MPH,0
9 MPH,286
9 MPH,236
9 MPH,0
9 MPH,72
9 MPH,249
9 MPH,286
9 MPH,241
9 MPH,0
9 MPH,286
9 MPH,0
9 MPH,253
9 MPH,72
9 MPH,286
9 MPH,72
9 MPH,72
9 MPH,254

Current schematic:

And the code:

volatile byte count;

unsigned int duration;

unsigned long timePrevious;

float windSpeed = 0;

int windVein = 0; 

void setup()
{
  Serial.begin(9600);
  attachInterrupt(0, arduino_anemometer, RISING);

  count = 0;
  duration = 0;
  timePrevious = 0;
}

void loop()
{
  
  windVein = (analogRead(windVein));
  if (count >= 1) { 
    duration = (millis() - timePrevious);
    timePrevious = millis();
    count = 0;
    windSpeed = (1492/duration);
    Serial.print(windSpeed,DEC);
    Serial.print(" MPH");
    Serial.print(",");
    Serial.println(windVein);
  }
}

void arduino_anemometer()
{
  count++;
}

Thanks!

Maybe you would want to filter the open circuit readings a little by adding a capacitor from A0 to GND...

Just a thought... don't put a ton of faith in my advice... it's not like I tried it yet.

Also - why only limit yourself to 8 cardinal directions? Instead of using the resistor array you have set up, print out on transparency sheets a variable density radial circle filter wheel (think of a radar sweep circle - for instance, dark at 12 o'clock, and as you sweep around clockwise, the darkness falls off linearly until it is clear/mostly clear @ 11:59); then, use a phototransistor or LDR to measure light as it falls through it - the variable density of the filter wheel would act as an optical 360 degree "potentiometer"...

Maybe you would want to filter the open circuit readings a little by adding a capacitor from A0 to GND...

Ok I just tried that, still sloppy.

 the variable density of the filter wheel would act as an optical 360 degree "potentiometer"...

I really like this idea, however my current setup is weatherproof and ready to go. Aside from the sloppy readings... :)

Interesting idea for an optical pot. You'd have to provide a light source as well.

Just out of curiosity, has anyone tried this device? http://www.sparkfun.com/commerce/product_info.php?products_id=9074

Shouldn't this line

windVein = (analogRead(windVein));

be inside the if statement, so you only read the vane position if count is greater than 1 ?

EDIT: And what about debouncing the switches in the vane ?

You analogRead is incorrect. The first time you will read from aport 0. You then overwrite the variable with the result. Next time you read from a random value.

Try changing to: windVein = (analogRead(0));

Just out of curiosity, has anyone tried this device?

#include <obvious_smart-assed_remark.txt>

I’ve seen a few postings from people who’ve used various forms of SoftPot/HotPot. Can’t remember whether they were favorable comments, offhand, but a forum search should turn them up.

The problem with using them for wind direction is that the drag from whatever you used to press on the HotPot would probably give you bogus direction readings at low wind speeds.

Ran

Hmm... yeah, good point about the drag.