const int THERMISTOR_PIN = 33; // Analog pin connected to the thermistor const double THERMISTOR_NOMINAL = 10000.0; // Thermistor resistance at nominal temperature (in ohms) const double TEMPERATURE_NOMINAL = 25.0; // Nominal temperature for the thermistor (in degrees Celsius) const double B_COEFFICIENT = 3950.0; // Beta coefficient of the thermistor const double SERIES_RESISTOR = 10000.0; // Value of the series resistor (in ohms) const unsigned long TIMER_DURATION = 600000; // 10 minutes in milliseconds const unsigned long twentyFourHours = 24UL * 60UL * 60UL * 1000UL; // Time in milliseconds for 24 hours unsigned long startTime; int averages[600]; double rollingAverages[600]; void setup() { Serial.begin(115200); // Initialize the serial communication startTime = millis(); // Record the starting time } double rollingAverage(int arr[600]) { int allData = 0; for (int i = 0; i < 600; ++i) { allData += arr[i]; } double average = allData / 600; return average; } double allTimeAverage(double rollingAverages[600]) { int temp = 0; for (int i = 0; i < 600; ++i) { temp += rollingAverages[i]; } double allTime = temp / 600; return allTime; } void loop() { unsigned long currentTime = millis(); // Get the current time int count = 0; // Calculate the elapsed time unsigned long elapsedTime = currentTime - startTime; while (currentTime - startTime < TIMER_DURATION && count < 600 && elapsedTime <= twentyFourHours) { int rawValue = analogRead(THERMISTOR_PIN); // Read the raw ADC value from the thermistor pin // Convert the raw value to resistance using the voltage divider formula double resistance = SERIES_RESISTOR * (4095.0 / rawValue - 1.0); // Calculate the temperature using the Steinhart-Hart equation double steinhart; steinhart = resistance / THERMISTOR_NOMINAL; // (R/R0) steinhart = log(steinhart); // ln(R/R0) steinhart /= B_COEFFICIENT; // (1/B) * ln(R/R0) steinhart += 1.0 / (TEMPERATURE_NOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert double temperature = steinhart - 273.15; // Convert to Celsius averages[count] = temperature; ++count; Serial.print("Temperature: "); Serial.print(temperature); Serial.println("°C"); delay(1000); // Delay for 1 second before reading again } if (elapsedTime >= twentyFourHours) { double a = allTimeAverage(rollingAverages); Serial.print("All Time Average: "); Serial.println(a); } double a = rollingAverage(averages); int j = 0; Serial.print("Rolling average: "); Serial.println(a); //store in rolling averages rollingAverages[j] = a; ++j; //reset count count = 0; startTime = millis(); // Restart the timer }