code to record wind speed

hello i am beginner in arduino and i have small project to record wind speed
i have this sensor to record wind speed

is this code right or compatible with above sensor
/*

Anemometer Tutorial

This code takes the output from an Adafruit anemometer (product ID 1733) and converts it into a wind speed.

Hardware instructions and background information can be found at: http://www.hackerscapes.com/2014/11/anemometer/

//Setup Variables

const int sensorPin = A0; //Defines the pin that the anemometer output is connected to
int sensorValue = 0; //Variable stores the value direct from the analog pin
float sensorVoltage = 0[/color]; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant = .004882814; //This constant maps the value provided from the analog read function, which ranges from 0 to 1023, to actual voltage, which ranges from 0V to 5V[/color]
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables
//The following variables correspond to the anemometer sold by Adafruit, but could be modified to fit other anemometers.

float voltageMin = .4;[/color] // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0;[/color] // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage



void setup() 
{              
 Serial.begin(9600);  //Start the serial connection
}


void loop() 
{
sensorValue = analogRead(sensorPin); //Get a value between 0 and 1023 from the analog pin connected to the anemometer

sensorVoltage = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage

//Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
if (sensorVoltage <= voltageMin){
windSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
}else {
 windSpeed = (sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
}

//Print voltage and windspeed to serial
 Serial.print("Voltage: ");
 Serial.print(sensorVoltage);
 Serial.print("\t"); 
 Serial.print("Wind speed: ");
 Serial.println(windSpeed); 

delay(sensorDelay);
}

thanks in advance

Please read the forum guidelines in the sticky post. They will tell you how to post code correctly, and links and pictures. Then please edit your post above and fix it.

To answer your question, no, this code is not suitable because it is designed for a very different design of anemometer. The AdaFruit sensor generates a voltage that changes with windspeed.. Your anemometer, like the one I use, generates pulses at a frequency that changes with the windspeed.

dear sir
thank very much for your replay i made necessary modification for my post
please can you help me how to write a suitable code that match with the nrg system

Thank you for correcting your post.

How do you want to use the anemometer? The simplest way is to time the interval between pulses. But the disadvantage is that you will be measuring every gust and lull in the wind. Maybe that is what you want, or maybe you want to calculate the average wind speed over a longer period so that gusts do not affect the reading?

You also have to be able to supply DC power to the anemometer.

Paul

Yes, but 5V is in the acceptable range, so that should be ok, as long as the wires are not too long.

thank you sir
actually i need to record average of wind speed for every 10 minutes

0 HZ=0.365 m/s
125 HZ=96 m/s
other wind speed calculated from this equation
m/s = (Hz x 0.765) + 0.35
signal type is square wave
the type of arduino is arduino mega

Ok, good.

First write a small sketch to read the input from the anemometer using digitalRead() and print the result to the serial monitor. You will need to set the digital pin mode to INPUT_PULLUP. As mentioned by the other Paul, you will need to connect 5V and ground to the Mega, and a digital pin of your choice. When you upload this code, you should see values alternating between "0" and "1" on the serial monitor as you turn the anemometer slowly by hand. This will prove that the anemometer is working, that the connections are correct and that the Mega can detect the square wave signal.

1 Like
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

Do you want my help? Do you trust me?

If you do, delete that code, go back and re-read post #7. Just try to do what I ask, nothing more. I will take you to the solution step by step, so you understand what you are doing and why at each step. There won't be too many steps, I promise.