# I need to find the Max value of an input over 24 hours

I have been working on my weather station, It consists of an arduino Uno, and an ethernet shield. The system will monitor wind speed, wind direction, temperature, and humidity. The unit is going on top of a mountain at about 8800 feet and we expect to see some extreme wind speeds, and don't want to miss them if we aren't looking at the Weather page. Im trying to create a function that will compare the Wind speed over 24 hours, and give me a "daily High Wind Speed", but I just cant quite wrap my head around the code to do it, I would greatly appreciate some help. here's what Ive got so far.

void getDailyHighSpeed (float speed){

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;

{
dailyHighSpeed = highSpeed;

if (highSpeed >= dailyHighSpeed){
dailyHighSpeed = highSpeed;
}else {
dailyHighSpeed = dailyHighSpeed;
}
Serial.println(dailyHighSpeed);
}

Is there a good reason that your function doesn't use its sole parameter?

From your calculation, it is not clear what the anenometer is delivering. I'd go back to basics.

The wind speed is a function of the number of rotations of the arm of the anemometer in unit time and the length of its arm.
If you want a 24 hour average, that unit time is 24 hours.
If you want a peak wind speed, you have to define a shorter time (say 10 seconds) over which that peak is measured/sampled.

If the anenometer delivers pulses, you simply count them and do the calculation over the required time period.
If the anenometer already gives some function of wind speed, you have to sample this at regular intervals to derive (a) the average wind speed over 24 hours and (b) the peak windspeed in a 24 hour period.

``````else {
dailyHighSpeed = dailyHighSpeed;
}
``````

WTF? Why do you think that this is even remotely necessary?

This should get you going it will read and store the max value it see’s on A0 input, But only while it remains powered. If you need to store then I would use SD card or EEProm if you loose power.
It’s a quick example and easily adopted to suit yours if I’ve understood it you correctly.

``````//####################################################
//# Include all the libraries                        #
//####################################################
#include <LiquidCrystal_I2C.h> // I2C LCD display only for intial setup
#include  <Wire.h> //Wire libary
//####################################################
//# Define the Variables                             #
//####################################################

float maxvolts = 0;
float mvoltsmax = 0;
LiquidCrystal_I2C lcd(0x027, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
void setup() {
lcd.begin(20, 4); // General LCD 2 x 8 with backlight
Wire.begin();  // join I2C bus
lcd.setCursor(0, 0);
lcd.print("POWERING");
lcd.setCursor(0, 1);
lcd.print("  UP  ");// Print something on the display to show
delay(1000);                                   // it's working.
lcd.clear();
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
maxvolts = getmaxvolts(voltage); //pass voltage variable to getmaxvolts function
// print out the value you read:
lcd.setCursor(0, 0);
lcd.print("Real voltage");
lcd.print(voltage, 2); //display in coming voltage
lcd.setCursor(0, 1);
lcd.print("Max voltage");
lcd.print(maxvolts, 2); //display the max volts
}

float getmaxvolts(float mvolts)
{
if (mvolts >= mvoltsmax)
{
mvoltsmax = mvolts;
}
return mvoltsmax;

}
``````