Arduino with an Anemometer: Measure Wind Speed

In this guide, you’ll learn how to use an anemometer with the Arduino board to measure wind speed. We’ll cover how to power and connect the sensor to the Arduino and write a simple code to get wind speed values in different units.

Arduino with an Anemometer: Measure Wind Speed

Table of Contents:

Throughout this guide, we’ll cover the following topics:

Introducing the Anemometer

An anemometer is a device that allows us to measure wind speed. It is commonly used in weather stations.

Using this sensor is quite easy. It outputs an analog signal, whose voltage is proportional to the wind speed. We’re using an anemometer with three cups like the one in the picture below.

Wind Sensor Anemometer

Anemometer Technical Details

Depending on the manufacturer and model, the anemometer may have different characteristics. For example, these are the characteristics of the anemometer used in this guide:

  • Input voltage: 12-24V DC
  • Output voltage: 0-5V
  • Measurement range: 0-32.4m/s
  • Resolution: +/- 0.3m/s

This means that when the analog signal is 0, the wind speed is 0. However, in my case, I noticed that when the anemometer was not moving, the output voltage was 0,054V and not 0V.

Arduino Measure Voltage from Wind Sensor with no wind

So, I consider this to be the lowest value measured when the sensor is not moving. I recommend you do the same and figure out the minimum value read from the sensor using a multimeter.

These details might be different for your specific model. So, you need to take that into account when converting the analog signal to wind speed.

Anemometer Pinout

The anemometer comes with three wires:

Blue WireSignal
Black WireGND
Brown WirePower
Anemometer, Wind Sensor Pinout

Connecting the Anemometer to the Arduino

The anemometer we’re using requires an input voltage of at least 12V. So, you can’t power it directly from the Arduino, you need an external power source.

12V DC Power Adapter

We’re powering the sensor using a 12V power adapter and connecting it to the anemometer using a power jack. You can use any other suitable power source.

DC power jack adapter

Wiring the Circuit: Arduino with Anemometer

Arduino with Anemometer Circuit

Here’s a list of the parts you need for this tutorial:

Wiring the sensor to the Arduino is quite simple. You just need to connect the data signal to an analog pin of the Arduino and connect the GNDs together.

Arduino with Wind Sensor Anemometer Circuit Diagram

In my case, I need to power the sensor using an external 12V power source.

Black WireGND of the Arduino and GND of the power source
Blue WireConnect to an analog pin. We’re using A0
Brown Wire12V power source (+)

Arduino with the Anemometer – Measure Wind Speed Code

The following code reads the analog signal from the anemometer and converts it into wind speed.

You can upload the following code to your Arduino board. You may need to modify some of the variables depending on the parameters of your anemometer.

/*********
  Rui Santos & Sara Santos - Random Nerd Tutorials
  Complete project details at https://RandomNerdTutorials.com/arduino-anemometer-measure-wind-speed/
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Softwar
*********/

// Constants (Change the following variables if needed)
const int anemometerPin = 0;  // analog pin 0 (A0)
const float minVoltage = 0.054;  // Voltage corresponding to 0 m/s
const float maxVoltage = 5;  // Voltage corresponding to 32.4 m/s (max speed)
const float maxWindSpeed = 32.4; // Maximum wind speed in m/s

// Conversion factors
const float mps_to_kmh = 3.6;   // 1 m/s = 3.6 km/h
const float mps_to_mph = 2.23694; // 1 m/s = 2.23694 mph

void setup() {
  Serial.begin(9600);  
}

void loop() {
  // Read analog value from anemometer (ADC value between 0-1023 on Arduino for 0-5V)
  int adcValue = analogRead(anemometerPin);
  
  // Convert ADC value to voltage (Arduino ADC range is 0-5.0V)
  float voltage = (adcValue / 1023.00) * 5.0;
  
  // Ensure the voltage is within the anemometer operating range
  if (voltage < minVoltage) {
    voltage = minVoltage;
  } else if (voltage > maxVoltage) {
    voltage = maxVoltage;
  }
  
  // Map the voltage to wind speed
  float windSpeed_mps = ((voltage - minVoltage) / (maxVoltage - minVoltage)) * maxWindSpeed;

  // Convert wind speed to km/h and mph
  float windSpeed_kmh = windSpeed_mps * mps_to_kmh;
  float windSpeed_mph = windSpeed_mps * mps_to_mph;

  // Print wind speed
  Serial.print("Wind Speed: ");
  Serial.print(windSpeed_mps);
  Serial.print(" m/s, ");
  Serial.print(windSpeed_kmh);
  Serial.print(" km/h, ");
  Serial.print(windSpeed_mph);
  Serial.println(" mph");
  
  delay(1000); 
}

View raw code

How does the Code Work?

First, define the pin where you’re reading the sensor (in our case A0), the minimum and the maximum output voltage of the sensor, and the maximum wind speed.

// Constants (Change the following variables if needed)
const int anemometerPin = 0;  // analog pin 0 (A0)
const float minVoltage = 0.054;  // Voltage corresponding to 0 m/s
const float maxVoltage = 5;  // Voltage corresponding to 32.4 m/s (max speed)
const float maxWindSpeed = 32.4; // Maximum wind speed in m/s

These are the parameters for our sensor. Yours might be different. When the sensor is not moving, it outputs a voltage of 0.054V, so we consider that the minimum value.

Then, we have the conversion factors to convert the wind speed from m/s to km/h and mph.

// Conversion factors
const float mps_to_kmh = 3.6;   // 1 m/s = 3.6 km/h
const float mps_to_mph = 2.23694; // 1 m/s = 2.23694 mph

In the setup(), we initialize the Serial Monitor.

void setup() {
  Serial.begin(9600);  
}

In the loop(), we get new readings from the sensor every second.

First, we read the value on the ADC pin and convert it to a voltage value. The maximum value read on the Arduino ADC pin is 1023 that corresponds to 5V. So, we can convert the value to a voltage using the following line:

// Read analog value from anemometer (ADC value between 0-1023 on Arduino for 0-5V)
int adcValue = analogRead(anemometerPin);
  
// Convert ADC value to voltage (Arduino ADC range is 0-5.0V)
float voltage = (adcValue / 1023.00) * 5.0;

Then, we have the following condition to check if the values read are within the defined range.

if (voltage < minVoltage) {
  voltage = minVoltage;
} else if (voltage > maxVoltage) {
  voltage = maxVoltage;
}

Next, we can easily map the obtained voltage to a wind speed value (alternatively, you can use the Arduino map() function).

float windSpeed_mps = ((voltage - minVoltage) / (maxVoltage - minVoltage)) * maxWindSpeed;

Then, we convert the values obtained to km/h and mph.

// Convert wind speed to km/h and mph
float windSpeed_kmh = windSpeed_mps * mps_to_kmh;
float windSpeed_mph = windSpeed_mps * mps_to_mph;

Finally, we print the obtained results.

  // Print wind speed
  Serial.print("Wind Speed: ");
  Serial.print(windSpeed_mps);
  Serial.print(" m/s, ");
  Serial.print(windSpeed_kmh);
  Serial.print(" km/h, ");
  Serial.print(windSpeed_mph);
  Serial.println(" mph");
  
  delay(1000); 
}

Testing the Code

Upload the code to your Arduino board. Make sure you have the sensor wired and powered properly.

Open the Serial Monitor at a baud rate of 9600.

Spin the sensor to mimic some wind, and see the values being printed in the Serial Monitor every second.

Testing Wind Sensor with Arduino - Serial Monitor Demonstration

And that’s it. Now, you can read the wind speed with your Arduino board. You can now add an anemometer to your weather station.

Wrapping Up

In this tutorial, you learned how to interface an anemometer with the Arduino board. This is a fundamental sensor to add to your weather station to get wind speed data.

We have tutorials for more than 30 sensors with the Arduino board. You can check them below:

We hope you found this tutorial useful. You may also like other related tutorials:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

1 thought on “Arduino with an Anemometer: Measure Wind Speed”

  1. Thanks for this!
    Can you please point out the pros and cons, of using an anemometer like the one in this tutorial (0-5V output) versus using one with RS485 output?

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.