# Measuring Wind Speed with an Arduino / Anemometer

A while back, we got a set of weather sensors from Sparkfun. It includes a Anemometer (speed), Wind Vane (direction), and a Rain Gauge.

I used a hand held wind speed device to calibrate my Arduino code.

I’m using pinMode(2, INPUT_PULLUP); so no pull up or pull down resistor is needed.

I used a prototype dual 6 pin phone jack from IC Breakout to connect the weather sensors to the Arduino.

For this sketch, I connected the two wires from the anemometer to pins 2 (interrupt 0) and ground.

Code:

``` // diameter of anemometer
float radius= 2.75; //inches from center pin to middle of cup```
``` float diameter = radius * 2; //inches from center pin to middle of cup
float mph;

int half_revolutions = 0;
int rpm = 0;
unsigned long lastmillis = 0;

void setup(){
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, rpm_fan, FALLING);
}

void loop(){
if (millis() - lastmillis == 1000){ //Update every one second, this will be equal to reading frequency (Hz).
detachInterrupt(0);//Disable interrupt when calculating
rpm = half_revolutions * 30; // Convert frequency to RPM, note: 60 works for one interruption per full rotation. For two interrupts per full rotation use half_revolutions * 30.
Serial.print("RPM =t"); //print the word "RPM" and tab.
Serial.print(rpm); // print the rpm value.
Serial.print("t Hz=t"); //print the word "Hz".
Serial.print(half_revolutions/2); //print revolutions per second or Hz. And print new line or enter. divide by 2 if 2 interrupts per revolution
half_revolutions = 0; // Restart the RPM counter
lastmillis = millis(); // Update lastmillis
attachInterrupt(0, rpm_fan, FALLING); //enable interrupt
mph = diameter * 3.14 * rpm * 60 / 63360;
//mph = mph * 3.5; // calibration factor for anemometer accuracy, adjust as necessary```
``` Serial.print("t MPH=t"); //print the word "MPH".
Serial.println(mph);
}
}
// this code will be executed every time the interrupt 0 (pin2) gets low.
void rpm_fan(){
half_revolutions++;
}```

Subscribe
Notify of
Inline Feedbacks
Michael Mesloh
2 years ago

Hello Steve Spence , I am concerned about the value 63360. Where does it come from? Is this a costant for the anemometer? Can you explain this value?
I know that for the anemometer shown in your picture above, a wind speed of 1.492 MPH (2.4 km/h) causes the switch to close once per second.

Brian Jenkins
2 years ago

Hey there! Steve no longer maintains this blog. As far as your question goes, he wrote the code, but maybe when I get a chance I’ll take a peek at it…

7 years ago

I think the first line of code incorrect. From centre pin to middle of the cup would be radius. Diameter would be twice that eg float diameter should be 5.5 inches.

5 years ago

Is it a perfectly working code ?

5 years ago

assuming diameter is 5.5", would the following be correct?

rpm * 60 * diam * 3.14 / 12 / 5280

5 years ago

mph = diam * 3.14 * rpm * 60 / 63360 should be correct. I will correct the code.

6
0