Hi Im using Anemometer as in the photo . It has 4 wires (black , blue, yellow and red one). I measured the DC Voltage with multimeter and shows that black is the Ground and yellow as output. So according to that connect the yellow to Analog output AO of Arduino and black one to the Arduino GND. I include the sample code that should shows the with speed and output Voltage. The voltage will range from 0.4V (0 m/s wind) up to 2.0V (for 32.4m/s wind speed).
I dont know why there are 4 wires from the Anemometer . I have doubt if I connect good and if the code is ok? Any help? Enclose some photos of the Anemometer and wires.
moderators note : changed code mode from text to c
I dont know why there are 4 wires from the Anemometer . I have doubt if I connect good and if the code is ok? Any help? Enclose some photos of the Anemometer and wires.
C:
/*
This code takes the output from an anemometer and converts it into a wind speed.
*/
#include <Wire.h>
//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; //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 = 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; // 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()
{
Serial.begin(9600); //Start the serial connection
}
void loop()
{
sensorValue = analogRead(A0); //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);
}
Last edited by a moderator: