The datasheet is in chinese so I used google translator and it seems understandable
/*
Arduino Wind Speed Meter Anemometer mph - Adafruit anemometer (product ID 1733).
Modified code created March 2016 from original code created by Joe Burg 11th November 2014 at http://www.hackerscapes.com/ with help from Adafruit forum users shirad
*/
//Initialise LCD display
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int serial_in;
//Setup Variables
double x = 0;
double y = 0;
double a = 0;
double b = 0;
const int sensorPin = A1; //Defines the pin that the anemometer output is connected
const int numReadings = 10; //Defines number of reading to calculate average windspeed
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int totalWind= 0; // the running total
int averageWind = 0; // the average
int inputPin = A1;
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 sensorVoltage2 = 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()
{
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
//Setup LCD display with welcome screen
lcd.begin(16, 2);
lcd.print("Geeky Gadgets");
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
// subtract the last reading:
totalWind = totalWind - readings[readIndex];
// read from the sensor:
readings[readIndex] = sensorValue;
// add the reading to the total:
totalWind = totalWind + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
sensorVoltage2 = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage
// if we’re at the end of the array…
if (readIndex >= numReadings) {
// …wrap around to the beginning:
readIndex = 0;
// calculate the average:
averageWind = totalWind / numReadings;
sensorVoltage = averageWind * 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.232694; //For voltages above minimum value, use the linear relationship to calculate wind speed.
}
}
//Max wind speed calculation
x = windSpeed * 0.88;
if (x >= y) {
y = x;
} else {
y = y;
}
//Max voltage calculation
a = sensorVoltage;
if (a >= b) {
b = a;
} else {
b = b;
}
//Print voltage and windspeed to serial
Serial.print("Voltage: ");
Serial.print(sensorVoltage);
Serial.print("Average: ");
Serial.print(averageWind);
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=");
lcd.setCursor(11, 0);
lcd.print(windSpeed);
lcd.setCursor(0, 1);
lcd.print(b);
lcd.setCursor(5, 1);
lcd.print(readIndex);
lcd.setCursor(7, 1);
lcd.print("Max=");
lcd.setCursor(11, 1);
lcd.print(y);
delay(sensorDelay);
}
Looking at you program, I see no time factor in any of the calculations that are supposed to give "wind speed". So, the program looks like a nice exercise, but cannot give a "speed" value.
groundFungus:
Wind speed is a function of the voltage output of the anemometer (a DC generator?).
From the Adafruit page in the OP.
Ok. I wonder about the DC generator. They show an output voltage at 0 wind speed, so there is some process going on other than generation. My anemometer needs 1 mph wind speed to begin turning, but then can go to almost zero wind and keep turning. Looks like theirs is similar. I looked for a graph for linearity in the PDF, but there is none, so I suspect it is like mine, a reed switch operated by a magnet turned by the rotator, but they add some electronics and that is the reason for the power going to the device.
So time is already incorporated in their voltage output. I looked for, but didn't fine how quickly the machine responds to wind changes. Like my machine, it is almost linear by design.
Such a still standing sensor has a friction to overcome in order to start. Once rotating it can rotate at really low speeds. This is the same for many different things. Getting a multi ton train rolling calls for forces but slowing down, it does not wanr to stop....
Sorry for the very late reply, Im a student and I had to go to school (GMT +8) Timezone.
Answers:
The Arduino is powered by a 9volts battery or sometimes a pc usb plug which gives out 5 - 10 volts (doesn't really changes the value when I tested it out)
Yes the Wind speed is a function of the voltage output of the anemometer. Based on my research the anemometer works by calculating how much voltage it gives in every turn.
Hi,
To get your code this far I'm surprised the problem has not occurred earlier.
Did you write your code in stages?
If so you must have some code that JUST reads the anemometer output and puts it on the Serial.print.
What output do you get with the anemometer held stationary?
With your existing code, if you short the analog input to gnd, what does your code indicate?
If inputA not equal to last_read
If inputA eq high
Then count++
Serialwrite count
Put your math here
}
}
Do other things
At the end of loop
lastread = inputA
} // end of loop
This will only increment when there is a change
Warning the above is NOT actual code.
Wind speed does not need to be measured constantly. You could dedicate 30 seconds out of every 3 minutes. In 30 seconds or less you can get a good sense of wind speed
We have the anemometer and the same type as well, The output ill get when the anemometer is held stationary the value increases which can go to 100+ or so.
I did what you did, I put the analog input to gnd and the results were different.
I made the anemometer stop from moving, then waited around 1 min then the output of the Wind speed: is 0. Then after a couple of minutes the windspeed when to 2 - 5. I think it is working but its taking so long to update.
I dont have an multimeter nor oscilloskope, since I have a spare arduino board, I decided to use that board and the results are still the same.
Here is the graph plot for the anemometer. (The inputPin is connected to A1)
sometimes the line is constant then suddenly it goes up (The anemometer is moving at a low speed because Im blowing it and I sometimes use a fan.)
if the anemometer is a DC generator, then all you get is a voltage output.
To use, connect the black wire to power and signal ground, the brown wire to 7-24VDC
Connector details:
Pin 1 - Power (brown wire),
Pin 2 - Ground (black wire),
Pin 3 - Signal (blue wire),
Pin 4 not connected
simply your code to only look at one thing.
if you just read the voltage, then you can verify that the device has an output and is working
instead of using Serial Monitor, try Serial Plotter
this is the code you posted with everything in loop taken out except the analog reading
/*
Arduino Wind Speed Meter Anemometer mph - Adafruit anemometer (product ID 1733).
Modified code created March 2016 from original code created by Joe Burg 11th November 2014 at http://www.hackerscapes.com/ with help from Adafruit forum users shirad
*/
//Initialise LCD display
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int serial_in;
//Setup Variables
double x = 0;
double y = 0;
double a = 0;
double b = 0;
const int sensorPin = A1; //Defines the pin that the anemometer output is connected
const int numReadings = 10; //Defines number of reading to calculate average windspeed
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int totalWind= 0; // the running total
int averageWind = 0; // the average
int inputPin = A1;
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 sensorVoltage2 = 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()
{
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
//Setup LCD display with welcome screen
lcd.begin(16, 2);
lcd.print("Geeky Gadgets");
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
//this serial print is copied here for the test
Serial.print("Voltage: ");
Serial.print(sensorVoltage);
/* comment out for test
// subtract the last reading:
totalWind = totalWind - readings[readIndex];
// read from the sensor:
readings[readIndex] = sensorValue;
// add the reading to the total:
totalWind = totalWind + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
sensorVoltage2 = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage
// if we're at the end of the array…
if (readIndex >= numReadings) {
// …wrap around to the beginning:
readIndex = 0;
// calculate the average:
averageWind = totalWind / numReadings;
sensorVoltage = averageWind * 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.232694; //For voltages above minimum value, use the linear relationship to calculate wind speed.
}
}
//Max wind speed calculation
x = windSpeed * 0.88;
if (x >= y) {
y = x;
} else {
y = y;
}
//Max voltage calculation
a = sensorVoltage;
if (a >= b) {
b = a;
} else {
b = b;
}
//Print voltage and windspeed to serial
Serial.print("Voltage: ");
Serial.print(sensorVoltage);
Serial.print("Average: ");
Serial.print(averageWind);
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=");
lcd.setCursor(11, 0);
lcd.print(windSpeed);
lcd.setCursor(0, 1);
lcd.print(b);
lcd.setCursor(5, 1);
lcd.print(readIndex);
lcd.setCursor(7, 1);
lcd.print("Max=");
lcd.setCursor(11, 1);
lcd.print(y);
*/ // comment out for test
delay(sensorDelay);
} // === end of loop ===
Thank you for answering my questions, it is actually working, and serial plotter is more accurate than numbers that were being displayed, I can really say that it is working because the moment I blew it with fan it took around 20 seconds to update and the serial plotter shows that its going up, then I made it stop spinning then once again it updated and when to 0.
Thank you for helping me everyone especially to you dave-in-nj, Thank you.