'SOS' help! [WINDSPEED MEASURING PROJECT] ARDUINO+ANEMOMETER+LCD DISPLAY(16x2)

Hello guys
I’m having an issue with the code that i’m using in my end of studies project’
The problem is … I’m getting some random readings , random wind speed readings without even plugin in the sensor to my arduino Uno.
For ex: 20, 50, 100 , 200 , …. And it keeps going.
This is the sketch that I’m using I think the problem is from it but I don’t know where exactly ,
Can you plz take a look at it and help me out if you can it would mean the world to me I need asap 
Here’s the sketch:

/*
Arduino Wind Speed Meter Anemometer
*/

//Initialise LCD display

#include <LiquidCrystal.h>

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

int serial_in;

//Setup Variables

double x = 0;
double y = 0;
const int sensorPin = A1; //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; //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
int sensorDelay = 2000; //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; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

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

void setup()
{

//Setup LCD display with welcome screen

lcd.begin(16,2);
lcd.print(“Institut Senia”);
lcd.setCursor(0,1);
lcd.print(“Windspeed Sensor”);
delay(2500);
lcd.clear();
lcd.setCursor(0,0);
Serial.begin(9600); //Start the serial connection

}

//Anemometer calculations

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)*2.23694);}

//Max wind speed calculation

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

//Print voltage and windspeed to serial

Serial.print(“Voltage: “);
Serial.print(sensorVoltage);
Serial.print(”\t”);
Serial.print("Wind speed: ");
Serial.println(windSpeed);

//Display Wind Speed results to LCD with Max wind speed

lcd.setCursor(0,0);
lcd.print(“Wind Speed mph”);
lcd.setCursor(0,1);
lcd.print(windSpeed);
lcd.setCursor(7, 1);
lcd.print(“Max=”);
lcd.setCursor(11, 1);
lcd.print(y);

delay(sensorDelay);
}

Please edit your previous post and use code Tags. Press also ctrl-T in the IDE to properly indent the code, this is not very readable as is.

Not sure the y = y; is super useful but no harm there.

Are you saying that when nothing is plugged into A1 your analoRead() returns weird values? thats totally normal, your pin is floating and gets all sorts of parasite noise. Put a wire to ground or 3.3V or 5V and then you should see a stable value.

Nice weather in Oran?? :slight_smile:

thanks for replying my friend, yes the weather is awesome in here

i’ve did that already i’ve pluged in the sensor to my but it’s the same problem

without even moving the fan getting readings unreal readings like 200 mph … 100 mph hhhhhhh

here’s the sketch again plz check if there’s no problem with it :frowning:

/*
Arduino Wind Speed Meter Anemometer
*/

//Initialise LCD display 

#include <LiquidCrystal.h>

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


int serial_in;


//Setup Variables

double x = 0;
double y = 0;
const int sensorPin = A1; //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; //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
int sensorDelay = 2000; //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; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

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

void setup() 
{

//Setup LCD display with welcome screen

lcd.begin(16,2);
lcd.print("Institut Senia");
lcd.setCursor(0,1);
lcd.print("Windspeed Sensor");
delay(2500);
lcd.clear();
lcd.setCursor(0,0);
Serial.begin(9600);  //Start the serial connection

}

//Anemometer calculations

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)*2.23694);} 

//Max wind speed calculation 

x = windSpeed; if (x >= y){
 y = x;
}else {
  y = y;
}
 
//Print voltage and windspeed to serial
 
  Serial.print("Voltage: ");
  Serial.print(sensorVoltage);
  Serial.print("\t"); 
  Serial.print("Wind speed: ");
  Serial.println(windSpeed);

//Display Wind Speed results to LCD with Max wind speed
 
lcd.setCursor(0,0);
lcd.print("Wind Speed mph"); 
lcd.setCursor(0,1);
lcd.print(windSpeed); 
lcd.setCursor(7, 1);
lcd.print("Max=");
lcd.setCursor(11, 1);
lcd.print(y);
 
 delay(sensorDelay);
}

It’s still unreadable - please press CTRL-T to indent…

Have you verified the formula?

float voltageConversionConstant = 0.004882814; is roughly 5V/1024. Are you sure you get the full 5V range ? Your comments seems to indicate you will get between 0.4mV and 2mV… are you sure those are mV or are they Volts ?? If so that will be way too small and if they are V you should use a different analog reference to get the full scale

Adafruit specifications are

To use, connect the black wire to power and signal ground, the brown wire to 7-24VDC (we used 9V with success) and measure the analog voltage on the blue wire. The voltage will range from 0.4V (0 m/s wind) up to 2.0V (for 32.4m/s wind speed). That’s it! The sensor is rugged, and easy to mount. The cable can easily disconnect with a few twists and has a weatherproof connector.

So it would appear it’s V not mV… what about powering it? Do you have a separate 9V min power supply (some clones do need 12V min)? Did you join the ground with your arduino ?

You should not go through Volts to do your maths, stay in integers and compare with whatever thresholds would be (between 0 and 1023)

Where does this formula come from?

windSpeed = ((sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin)*2.23694);

Are you using this device ? :

If so, (a) it has this comment:

To use, connect the black wire to power and signal ground, the brown wire to 7-24VDC (we used 9V with success) and measure the analog voltage on the blue wire. The voltage will range from 0.4V (0 m/s wind) up to 2.0V (for 32.4m/s wind speed). That's it!

and (b) how are you connecting it ?

You have probably seen this code:
http://www.hackerscapes.com/2014/11/anemometer/

yes 6v6 i'm doing that exact project

and i'm using that sketch also

but i'm not using the windspeed sensor

i'm not using the adafruit one

:frowning: tell me what to do guys

:frowning: tell me what to do guys

Second time I'm asking: start by fixing the comments and the indentation of the code; it's ugly. ugly code can't be maintained nor debugged and I won't read it again if it's not fixed.

then answer the questions above that we already raised:

  • do you give enough power (I'd say go for 12v) to the anemometer?
  • did you wire common GND between your Arduino and the anemometer?
  • Where does the formula come from? can you explain it exactly?
  • are you loosing precision by going to float?

You've seen that the output voltage from the anemometer is between 0.4V and 2V. so there is no need to waste ADC precision trying to go all the way to 5 volts. Read about AnalogReference and set it to 3.3V for example or 2.56 V if you are on a MEGA. Then understand what it means for your math formulas to calculate the speed of course.

Then use your brain try to segment the problem. Start by printing out the information you get from AnalogRead(). is that consistent with observation ?

Don't just sit on your hands, do some research. You're a grown up by now. Take responsibility and action!

Thanks for replying again JML, i appreciate that brother.

Yes, i took the 12V supply power

And i did also wire common GND between my arduino and anemometer,

Like i've said before it's me who wrote the sketch, i'm just using it.

I don't understand the last question.

And i don't know how to fix the comments more than this,

Post a link to your anemometer. There are different types. Some produce an increasing voltage on higher wind speed. Some deliver pulses. The code you have is for the "voltage" type. It can, if necessary, be modified for a pulse type.

If you have simply taken a formula from a sketch for a specific anemometer, you'll probably anyway have to adjust it, at least to match the arm length

King-Mohamed:
i'm not using the adafruit one

:frowning: tell me what to do guys

Give us technical details of the anemometer you are using, or a link.

Same crappy comments in the slightly modified code here

Voltage for the adafruit anemometer is commented as mV and y=y. Apparently it works so I guess the problem is a different type of anemometer.

Looks like you don't want to learn how to program, have no interest in investing efforts and you put the blame on a code you copied from the web...

That's not how things work here

Thank you all for replying to me, i appreciate that from the bottom of my heart.

Here’s the one i’m using nx2 wind transducer tf

[Some produce an increasing voltage on higher wind speed. Some deliver pulses]

How to know the type of the anemometer that i have ?

@JML i’m just a student trying to get my superior technician diploma, we didn’t study this stuff at all …my teachers don’t even know how to program … don’t judge the book by it’s cover :confused:

sure - I don't see much of your personal work, contribution, research to debug, etc... seems you are expecting ready to use code...

I learned lot of stuff while trying to do this project,

I modified some stuff, but i'm still a noob in programming so i can't create a program on my own,

If you're willing to help, go ahead i'll appreciate it, if you're here to bug me because i'm asking for help, you should go somewhere else and do that.

I didn't do anything wrong except asking for help and pointers.

I’m not here to bug you - come on! read above — I’m encouraging you to take control of your challenge and the best way for that is to learn about programing so that you become self sufficient - so do the tutorials so that you know how to print what the sensors read, explore and test etc

You’ll see that this is very gratifying.

So do you have a link to the exact nx2 wind transducer tf thingy you use? is that the one you have??????

I do that on daily basesn,

I spent all day trying to make it work by myself!

I couldn't , i tried and tried and tried still nothing

I need to deliver my project in the 26th of this month, i'm already late, so late...

This is why i came here asking you guys for help, i had some crazy problems i couldn't focus on it before,

But now i'm forced to, since i have no time left,

Always the same problem, i plug in my windspeed sensor to my arduino i get no results, i tried with the pointers you gave me, still nothing

I don't know what's the problem i'm confused, tired i don't know what to say :frowning:

Here's the one i'm using nx2 wind transducer tf

Is it this one? http://www.hellasmarine.com/Nexus%20Manuals%20pdf/NX2/NX20728-1WindtransdEng.pdf

If so, it's meant to be integrated with a Nexus server (or possibly a stand alone Nexus display instrument for that sensor).

The system uses RS485 communication, and the messages are not documented.

Given your level of experience I think you will find it difficult to integrate this sensor with an Arduino.

give us a link to the real hardware you have
show us a picture

The wind speed is given by the
formula:
hv = ( f/3,4 ) + 0,3
Where f = frequency for channel A or B. Because of friction there is an offset
error of 0,3 m/s, i.e. if we measure 3,4 Hz the wind speed is 1 + 0,3 (1,3 m/s),
6,4 Hz gives 2 + 0,3 (2,3 m/s), 34 Hz gives 10 + 0,3 (10,3 m/s) and so on.
Pulsequotas (quota time high/frequency) in percent (QA%, QB%) is given by the
formula:
QA% = 50 % + 30 % x sinus (α) (cosinus (α) = sinus (α + 90°)
QB% = 50 % + 30 % x cosinus (α) α = wind angle
The two outputs are of the type open collector, i.e. there is a demand of a pull-up
resistor to get out an output signal.
Recommended value: 5 - 10 kΩ

screen GND, green +12V, white and yellow signals. For only windspeed yellow or white can be used, but you need to learn to measure frequency.

yes it is this one indeed