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