int sensorValue = 0; //Variable stores the value direct from the digital pin
float sensorfreq = 0; //Variable that stores the freq (in hz) from the anemometer being sent to the digital pin
float windSpeed = 0; // Wind speed in meters per second (m/s)
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)
float freqMin = 0; // Mininum output freq from anemometer in hz.
float windSpeedMin = 0.35; // Wind speed in meters/sec corresponding to minimum hz
float freqMax = 125; // Maximum output frq from anemometer in hz.
float windSpeedMax = 96; // Wind speed in meters/sec corresponding to maximum freq
void setup()
{
pinMode(2, INPUT_PULLUP)
Serial.begin(9600); //Start the serial connection
}
void loop()
{
int sensorValue = digitalread(2); //
if {(sensorvalue<=freqmin)
windspeed=0.35;//Check if freq is below minimum value. If so, set wind speed to zero.
}
else{
windspeed=(sensorvalue*0.765)+0.35//for freq.above minimum value use the linear relationship to calculate wind speed.
}
//Print frq and windspeed to serial
Serial.print("freq: ");
Serial.print(sensorvalue);
Serial.print("\t");
Serial.print("Wind speed: ");
Serial.println(windSpeed);
delay(sensorDelay);
}
i hope that this code is ok
note:input signal is square wave