Anemometer & Mkr board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Anemometer & Mkr board

by weal on Wed May 05, 2021 1:40 am

I'm using Adafruit Anemometer Wind Speed Sensor w/Analog Voltage Output with Mkr zero.
I was searching on the internet for code suitable for Anemometer and I have found this code but every time I use it with Mkr, I have got zero reading compared with using it with Arduino.
I had to change the code in this line
float voltageConversionConstant = 0.00080586;//(3.3/4095)

Could anyone please help me? what's wrong in the code?
How to convert 3.3 = 0-4095 into voltage?

Code: Select all | TOGGLE FULL SIZE
#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 = 0.00080586;//(3.3/4095)
//float voltageConversionConstant = .004882814; //(5/1024)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("Wind speed: ");

Posts: 66
Joined: Sun Sep 29, 2019 12:30 am

Re: Anemometer & Mkr board

by blnkjns on Wed May 05, 2021 5:12 am

To read 12-bit, you need to tell the chip to use 12-bit input:
https://www.arduino.cc/reference/en/lan ... esolution/
So add this to your setup:
Code: Select all | TOGGLE FULL SIZE

Posts: 638
Joined: Fri Oct 02, 2020 3:33 am

Please be positive and constructive with your questions and comments.