Page 1 of 1

Using WH1080 wind sensors with custom weather station

Posted: Mon 11 Nov 2013 11:41 am
by shrx
Hello,
is it possible to use the WH1080 wind sensors (direction and speed) with a custom-built weather station? Is there any technical information available about these sensors, like wiring diagrams and interface instructions?

Re: Using WH1080 wind sensors with custom weather station

Posted: Mon 11 Nov 2013 2:46 pm
by Charlie
Yes it's possible, and all the information is here on the forum. Start with the search button. We'll be happy to help if you have questions.

Re: Using WH1080 wind sensors with custom weather station

Posted: Tue 12 Nov 2013 10:12 pm
by Werk_AG
Yes, it´s possible :D

In this link you will find the datasheet you asked: WH1080 datasheet

At this page you can find a nice piece of code for reading this sensors with an Arduino:
Sparkfun Weather Station

I have used this info to made my custum-built weather station: WeatherDuino Pro2.
It is working since some months wihout any major problem.
I have not implemented or tested the code for the rain gauge, because I'm using another type of rain gauge.

Hope this help

Re: Using WH1080 wind sensors with custom weather station

Posted: Tue 12 Nov 2013 10:59 pm
by shrx
Thank you for your replies. It's great to see there are already existing solutions so I won't have to start from scratch.

Re: Using WH1080 wind sensors with custom weather station

Posted: Thu 28 Nov 2013 10:50 pm
by shrx
I have received the sensors (both wind sensors and the rain gauge as well) this week and started working on them. I have used the code provided here to read data from the sensors with an arduino:

Code: Select all

// Set up the inputs and the interrupts

#define ANEMOMETER_PIN 3
#define ANEMOMETER_INT 1
#define VANE_PWR 4
#define VANE_PIN A0
#define RAIN_GAUGE_PIN 2
#define RAIN_GAUGE_INT 0

void setup() {
  Serial.begin(9600);
}
 
void setupWeatherInts()
{
  pinMode(ANEMOMETER_PIN,INPUT);
  digitalWrite(ANEMOMETER_PIN,HIGH);  // Turn on the internal Pull Up Resistor
  pinMode(RAIN_GAUGE_PIN,INPUT);
  digitalWrite(RAIN_GAUGE_PIN,HIGH);  // Turn on the internal Pull Up Resistor
  pinMode(VANE_PWR,OUTPUT);
  digitalWrite(VANE_PWR,LOW);
  attachInterrupt(ANEMOMETER_INT,anemometerClick,FALLING);
  attachInterrupt(RAIN_GAUGE_INT,rainGageClick,FALLING);
  interrupts();
}

// ---------------------
// Wind speed (anemometer)

#define WIND_FACTOR 2.4
#define TEST_PAUSE 60000
 
volatile unsigned long anem_count=0;
volatile unsigned long anem_last=0;
volatile unsigned long anem_min=0xffffffff;
 
double getUnitWind()
{
  unsigned long reading=anem_count;
  anem_count=0;
  return (WIND_FACTOR*reading)/(TEST_PAUSE/1000);
}
 
double getGust()
{
 
  unsigned long reading=anem_min;
  anem_min=0xffffffff;
  double time=reading/1000000.0;
 
  return (1/(reading/1000000.0))*WIND_FACTOR;
}
 
void anemometerClick()
{
  long thisTime=micros()-anem_last;
  anem_last=micros();
  if(thisTime>500)
  {
    anem_count++;
    if(thisTime<anem_min)
    {
      anem_min=thisTime;
    }
 
  }
}

// ---------------------
// Wind direction (vane)

static const int vaneValues[] PROGMEM={66,84,92,127,184,244,287,406,461,600,631,702,786,827,889,946};
static const int vaneDirections[] PROGMEM={1125,675,900,1575,1350,2025,1800,225,450,2475,2250,3375,0,2925,3150,2700};
 
double getWindVane()
{
  analogReference(DEFAULT);
  digitalWrite(VANE_PWR,HIGH);
  delay(100);
  for(int n=0;n<10;n++)
  {
    analogRead(VANE_PIN);
  }
 
  unsigned int reading=analogRead(VANE_PIN);
  digitalWrite(VANE_PWR,LOW);
  unsigned int lastDiff=2048;
 
  for (int n=0;n<16;n++)
  {
    int diff=reading-pgm_read_word(&vaneValues[n]);
    diff=abs(diff);
    if(diff==0)
       return pgm_read_word(&vaneDirections[n])/10.0;
 
    if(diff>lastDiff)
    {
      return pgm_read_word(&vaneDirections[n-1])/10.0;
    }
 
    lastDiff=diff;
 }
 
  return pgm_read_word(&vaneDirections[15])/10.0;
 
}

// ---------------------
// Rain gauge

#define RAIN_FACTOR 0.2794
 
volatile unsigned long rain_count=0;
volatile unsigned long rain_last=0;
 
double getUnitRain()
{
 
  unsigned long reading=rain_count;
  rain_count=0;
  double unit_rain=reading*RAIN_FACTOR;
 
  return unit_rain;
}
 
void rainGageClick()
{
    long thisTime=micros()-rain_last;
    rain_last=micros();
    if(thisTime>500)
    {
      rain_count++;
    }
}

// ---------------------
// Main loop

void loop() {
  Serial.println(getUnitWind());
  Serial.println(getGust());
  Serial.println(getWindVane());
  Serial.println(getUnitRain());
  Serial.println(" ");
  delay(10000);
}
However the serial readings are always the same, even if I manually turn the sensors which should trigger interrupts and change the internal resistance of the wind vane:

Code: Select all

0.0
0.0
270.0
0.0
Can you help me finding possible bugs in the code? I am only a beginner in coding for arduino.

Re: Using WH1080 wind sensors with custom weather station

Posted: Tue 03 Dec 2013 6:05 pm
by Werk_AG
After a quick look at your code, you need at least init your weather instruments once.
Try call void setupWeatherInts() on setup section.

Re: Using WH1080 wind sensors with custom weather station

Posted: Tue 03 Dec 2013 6:35 pm
by shrx
Yes, I forgot to write an update for this. It can be solved with movng everything in "setupWeatherInts" to "setup".