Anemometer & Mkr board

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)

How to convert 3.3 = 0-4095 into voltage?

Code: Select all | TOGGLE FULL SIZE
`#include <Wire.h>//Setup Variablesconst int sensorPin = A0; //Defines the pin that the anemometer output is connected toint sensorValue = 0; //Variable stores the value direct from the analog pinfloat sensorVoltage = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pinfloat 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 5Vint 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 voltagefloat voltageMax = 2.0; // Maximum output voltage from anemometer in mV.float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltagevoid 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 anemometersensorVoltage = 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 anemometerif (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);}`

weal

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

Re: Anemometer & Mkr board

To read 12-bit, you need to tell the chip to use 12-bit input:
https://www.arduino.cc/reference/en/lan ... esolution/
`analogReadResolution(12);`