How to Hookup Davis Anemometer to Arduino (Part 1 of 3)

Overview

This three part tutorial covers the interfacing of the Davis Anemometer to the Arduino. In the first part we cover the detection of the wind direction. In Part 2 we go through how to measure the wind speed. In the final part we update the software to measure both wind speed and direction and provide some other functionality.

For product details including circuit diagrams then click here.

Parts List

  • Arduino Board
  • Davis Anemometer
  • 4K7 Pullup Resistor
  • Breadboard hookup wires
  • USB Cable to suite Arduino
  • A compass for calibrating wind direction

Wiring Diagram for connecting the Davis Anemometer to an Arduino Board

Connect Arduino to Davis Anemometer

There are two connections to the Arduino. The Wind speed circuit is connected to a digital pin (Pin 2 in this case) and the wind direction circuit is connected to an analog pin (Ananlog Pin 4).

The wind speed circuit is a switch that is activated once revolution of the wind cups. In this hookup we are using a 4.7K pullup resistor. This will pull the pin 2 to 5V when the switch is open. If we don't use a pullup resistor the circuit voltage could float and cause false triggers on the input. When the mercury switch on the wind cups close then the pin 2 will be pulled to GND for a short duration while the magnet passes the switch. We use this pulse on pin 2 of the Arduino to detect every time the wind cups goes through one revolution. In Part 2 of this tutorial we go into more detail on measuring the wind speed.

How to Detect the Wind Direction

The wind vane has a 20k linear potentiometer attached to it. The output from the wind direction circuit is connected to a analog pin on the Arduino. As we move the wind vane around we should get a reading between 0 and 1023. The Arduino has a 10 bit A to D converter which gives us the range of 0 to 1023. This would also correspond to a voltage of 0 to 5V. In the software we need to convert the 0 to 1023 to a 0 to 360 range to give us the wind direction.

The potentiometer in the wind vane has a dead band that will result in the value 0 on the analog pin. The diagram below shows the dead band for the Davis anemometer we were using for testing. In this image we are looking down over the top of the wind vane. The anemometer is resting on the cups.

Davis Wind Direction Compass Headings

The wind vane is calibrated from the factory to be 0 when the vane is lined up along the length of the support bar pointing away from the mounting bracket.

Wind Direction Sketch

We can use this sketch to read the output from the wind vane. The sketch reads the analog pin value. We then convert the 0 to 1023 range to a direction value that ranges from 0 to 360. We use the map command to translate the two value ranges. We are using the offset value of 0 on line 5 as we are have the support arm pointing to magnetic north. We discuss the calibration of the wind vane below.

Davis Wind Direction Sketch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
int VaneValue;// raw analog value from wind vane
int Direction;// translated 0 - 360 direction
int CalDirection;// converted value with offset applied
int LastValue;

#define Offset 0;

void setup() {
LastValue = 1;
Serial.begin(9600);
Serial.println("Vane Value\tDirection\tHeading");
}

voidloop() {
VaneValue = analogRead(A4);
Direction = map(VaneValue, 0, 1023, 0, 360);
CalDirection = Direction + Offset;

if(CalDirection > 360)
CalDirection = CalDirection - 360;

if(CalDirection < 0)
CalDirection = CalDirection + 360;

// Only update the display if change greater than 2 degrees.
if(abs(CalDirection - LastValue) > 5)
{
Serial.print(VaneValue); Serial.print("\t\t");
Serial.print(CalDirection); Serial.print("\t\t");
getHeading(CalDirection);
LastValue = CalDirection;
}
}

// Converts compass direction to heading
void getHeading(int direction) {
if(direction < 22)
Serial.println("N");
else if (direction < 67)
Serial.println("NE");
else if (direction < 112)
Serial.println("E");
else if (direction < 157)
Serial.println("SE");
else if (direction < 212)
Serial.println("S");
else if (direction < 247)
Serial.println("SW");
else if (direction < 292)
Serial.println("W");
else if (direction < 337)
Serial.println("NW");
else
Serial.println("N");
}

The output from the sketch is the vane output value (0 - 1023) in the first column and the translated direction value (0 - 360) in the second column. At this stage the vane output value of 0 will correspond to a direction value of 0. Likewise the vane output value of 1023 will display as 360 in the direction column.

Arduino to Davis Wind Direction Sketch Output

This sketch output was generated by rotating the wind vane by hand.

Calibrating the Wind Direction

The simplest way to set up the anemometer for wind direction calibration is to have the mounting arm pointing directly to north on the compass. This means the direction that is obtained by converting the analog input value to a direction value will line up correctly with North. However if you are unable to point the mounting arm to magnetic north then we need to apply an offset to our wind direction calculation to correct the wind direction reading.

Davis Wind Direction Offset

To determine the offset to apply we need to point the wind vane to magnetic north. Using a compass we can determine the angle offset from the wind vane to the support bar. The 0 to 1023 output value from the wind vane stays relative the metal support bar. We then translate the 0 - 1023 value to a 0 - 360 value it is still relative to the support bar. However our magnetic north heading is now 40 degrees to the left of the support bar.

In the situation in the diagram above we need to add 40 to the translated wind direction so that our direction reading is now showing the calibrated wind direction. In the sketch we now need to supply the offset value. To do this change the value on line 5 to #define Offset 40. In the situation below we need to subtract -45 from the wind direction. We need to set the offset on line 5 to #define Offset -45.

Davis Wind Direction Offset

If the magnetic north heading relative to the support bar is between 0 to 180 then we subtract the offset from the Direction output to get the adjusted wind direction.

If the magnetic north heading relative to the support bar is between 181 to 360 then we add the offset to the Direction output to get the adjusted wind direction.

This is not the only way to calibrate the wind direction but it works for the way we calculate wind direction in the software.

In the next part of the tutorial we discuss how to measure wind speed.


License