Analog Wind Direction Sensor

How to Use Wind Direction Sensor with Arduino

We will learn how to use this analog wind direction sensor. If you need a tutorial about compass sensors, I already made one here. This is a Chinese wind direction sensor, sometimes it is just really hard to get the datasheet, or we can’t read the datasheet in Chinese. Let’s see the specification first, I don’t read Chinese but I think the label means operating voltage or voltage input is 12-24 volt. And the output is 0-5 volt.

Arduino with Analog Wind Direction Sensor Wiring Diagram

So it got a connector on the sensor. Let’s just plug the cable into the sensor and turn the connector several times.

The cables output has 3 wires. As we can guess it is VCC, ground, and analog output. From the color, we can guess that red for VCC, black for ground and yellow is the output.

So here’s the wiring diagram.

Analog Wind Sensor with Arduino
Analog Wind Direction Sensor with Arduino

Now just connect the power cables to the 12-24V power source, I use the 12V power source. And connect the analog output to the analog input of Arduino. I use analog zero. Once the wiring is completed. Now head to Arduino IDE.

In the code, I will read the analog value from A0 of Arduino and map the ADC result from 0-1023 to 0-360. Here’s the complete code.

The Code / Sketch

/* Wind Direction Sensor Sample
    Created by miliohm.com */

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  float voltage = sensorValue*5/1023.0;
  int direction = map(sensorValue, 0, 1023, 0, 360);
  // print out the value you read:
  Serial.print("ADC : ");
  Serial.println(sensorValue);
  Serial.print("Voltage : ");
  Serial.println(voltage);
  Serial.print("Direction : ");
  Serial.println(direction);
  delay(300); 
}

Now you can rotate the sensor while watching the serial monitor. We can see the direction degree changing there. See you in another tutorial. Here’s the complete video tutorial :