Arduino Uno Wind Speed Way 1

#include “TimerOne.h” // Timer Interrupt set to 2 second for read sensors
#include <math.h>
#include <Time.h>

// speed ok near speed-3.ino

#define WindSensorPin (2) // The pin location of the anemometer sensor
char wind[10]; //empty array where to put the numbers going to the master

int LastValue;
//int wind = 0;
volatile bool IsSampleRequired; // this is set true every 2.5s. Get wind speed
volatile unsigned int TimerCount; // used to determine 2.5sec timer count
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // speed miles per hour
byte x = 0;

void setup() {
Serial.begin(19200);
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
Serial.println(“Davis Anemometer Test”);
Serial.println(“Speed (MPH)tKnotstDirectiontStrength”);
Timer1.initialize(500000);
Timer1.attachInterrupt(isr_timer);

}

void loop() {
if(IsSampleRequired)
{
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/2.5) = P * 0.9
WindSpeed = Rotations * 0.48;

Rotations = 0; // Reset count for next sample
// wind = WindSpeed;

IsSampleRequired = false;

Serial.print(WindSpeed); Serial.println(“tt”);
// Serial.print(getKnots(WindSpeed)); Serial.print(“t”);
// Serial.print(CalDirection);
// getHeading(CalDirection); Serial.print(“tt”);
// getWindStrength(WindSpeed);

}
}
void isr_timer() {

TimerCount++;

if(TimerCount == 5)
{
IsSampleRequired = true;
TimerCount = 0;
}
}
void isr_rotation () {

if ((millis() – ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}

ref:http://cmfc-weatherstation.blogspot.com/2016/