Wind sensor project

so i am making a weather station,
and i currently got everything done except for the wind sensor
i am using a normal motor and i am using this code

/*
    Wind speed + LCD example
  
    Using an anemometer to measure wind speed in m/s.
    The wind speed is then displayed on a LCD

    (c) 2019 Karl, Josefine & David for Arduino

    based on code by Joe Burg (c) 2014

*/

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

double x = 0;
double y = 0;
double a = 0;
double b = 0;

int windSensor = A1;
float voltageMax = 2.0;
float voltageMin = .2;
float voltageConversionConstant = .004882814;
float sensorVoltage = 0;

float windSpeedMin = 0;
float windSpeedMax = 32;

int windSpeed = 0;
int prevWindSpeed = 0;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorValue = analogRead(windSensor);

  float voltage = sensorValue * (5.0 / 1024.0);

  sensorVoltage = sensorValue * voltageConversionConstant;



  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)) * 2.232694; //For voltages above minimum value, use the linear relationship to calculate wind speed.
  }

  x = windSpeed;
  if (x >= y) {
    y = x;
  } else {
    y = y;
  }

  //Max voltage calculation

  a = sensorVoltage;
  if (a >= b) {
    b = a;
  } else {
    b = b;
  }
  if (windSpeed != prevWindSpeed) {
    Serial.println(windSpeed);
    Serial.println(sensorVoltage);
    prevWindSpeed = windSpeed;
  }
  
  lcd.setCursor(0, 0);
  lcd.print("Wind Speed ");
  lcd.setCursor(12, 0);
  lcd.print(windSpeed);
  lcd.print(" ");
  lcd.setCursor(11, 2);
  lcd.print("m/s");
  delay(100);
}

the code works fine but idk i feel like the readings arent accurate, is there a way to make sure the readings are accurate? and i'd also like to have it read the average wind speed and not for every gust of wind

If you Google for "normal motor" what do you get? Do you have a small motor with permanent magnets for the field poles and an armature with brushes to conduct the electricity that is produced? If so, then such a wind speed measuring system is notorious for error. The slower air speed, the greater the error.

The classic way to calibrate such a device is to have someone drive a car while you hold the motor and propeller out a window and write down the resulting voltage from the motor while the car goes steadily at different speeds.

Then you can write your wind speed program and match the voltage readings to the table you created from the car drive.

Paul

Paul_KD7HB:
If you Google for "normal motor" what do you get? Do you have a small motor with permanent magnets for the field poles and an armature with brushes to conduct the electricity that is produced? If so, then such a wind speed measuring system is notorious for error. The slower air speed, the greater the error.

The classic way to calibrate such a device is to have someone drive a car while you hold the motor and propeller out a window and write down the resulting voltage from the motor while the car goes steadily at different speeds.

Then you can write your wind speed program and match the voltage readings to the table you created from the car drive.

Paul

idk exactly but it can spin very easily without any friction, so i am pretty positive its brushless

One traditional way of calibrating a wind sensor is to hold it out of a car window on a day with no wind, drive at various speeds and see if the sensor agrees with the car speedometer. How well it works depends on what is driving the motor (propeller, cups, fan etc) and the type of motor.

Averages are easy. Take a number of readings, add them together then divide by the number of readings. It's up to you to decide how long you want to average for. 10 minutes is fairly standard for weather forecasting but shorter or longer periods can be used. Then you can work out how many readings you need to average.

Steve

slipstick:
One traditional way of calibrating a wind sensor is to hold it out of a car window on a day with no wind, drive at various speeds and see if the sensor agrees with the car speedometer. How well it works depends on what is driving the motor (propeller, cups, fan etc) and the type of motor.

Averages are easy. Take a number of readings, add them together then divide by the number of readings. It's up to you to decide how long you want to average for. 10 minutes is fairly standard for weather forecasting but shorter or longer periods can be used. Then you can work out how many readings you need to average.

Steve

slipstick:
One traditional way of calibrating a wind sensor is to hold it out of a car window on a day with no wind, drive at various speeds and see if the sensor agrees with the car speedometer. How well it works depends on what is driving the motor (propeller, cups, fan etc) and the type of motor.

Averages are easy. Take a number of readings, add them together then divide by the number of readings. It's up to you to decide how long you want to average for. 10 minutes is fairly standard for weather forecasting but shorter or longer periods can be used. Then you can work out how many readings you need to average.

Steve

ik how averages work on paper, problem is how do i have it count how many readings it has

how do i have it count how many readings it has

Start with count set to zero.

Every time you make a reading, add one to count.

jremington:
Start with count set to zero.

Every time you make a reading, add one to count.

do you have like a code to demonstrate please?

int count=0,x;
x = read_sensor();
count++;

I attempted a similar project 2 years ago - not successful. In my area winds are to weak to accurately measure by a hobby diy propeller-based meter.

Now, if I have to tinker such an annoying thing, I will use the old principle of a wing which rises proportionally to wind velocity (see attached).

Although is not so sturdy, this is much easier to build and there are a lot of method to measure the mechanical movement.

jremington:

int count=0,x;

x = read_sensor();
count++;

could you explain further

The code is self-explanatory and performs the actions outlined in reply #5.