const int thermistorPin = 34; // Analog pin connected to the thermistor const int resistorValue = 10000; // Resistance value of the resistor const int bufferSize = 10800; // Size of the circular buffer float buffer[bufferSize]; // Circular buffer to hold the temperature readings int writeIndex = 0; // Index to write the next reading int numReadings = 0; // Number of readings currently stored float highestValue = -273.15; // Initialize with lowest possible temperature float lowestValue = 1000.0; // Initialize with highest possible temperature float overallAverage = 0.0; unsigned long startTime = millis(); // Start time in milliseconds unsigned long tenMinuteInterval = 600000; // 10 minutes in milliseconds unsigned long previousIntervalTime = 0; // Time of the previous 10-minute interval void setup() { Serial.begin(115200); } void loop() { // Read the analog value from the thermistor int rawValue = analogRead(thermistorPin); // Convert the raw value to resistance float voltage = rawValue * (3.3 / 4095.0); // Convert raw value to voltage (assuming 3.3V reference) float resistance = (resistorValue * voltage) / (3.3 - voltage); // Calculate the temperature in Celsius using the Steinhart-Hart equation float steinhart; steinhart = log(resistance / 10000.0); // (R/Ro) steinhart /= 3950.0; // 1/B * ln(R/Ro) steinhart += 1.0 / (25 + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // Convert to Celsius // Store the temperature reading in the circular buffer buffer[writeIndex] = steinhart; writeIndex = (writeIndex + 1) % bufferSize; // Update the number of readings stored (limited to bufferSize) numReadings = min(numReadings + 1, bufferSize); // Update the highest and lowest values highestValue = max(highestValue, steinhart); lowestValue = min(lowestValue, steinhart); // Calculate the overall average overallAverage = ((overallAverage * (numReadings - 1)) + steinhart) / numReadings; // Check if a 10-minute interval has elapsed unsigned long currentTime = millis(); if (currentTime - previousIntervalTime >= tenMinuteInterval) { // Output the 10-minute average float tenMinuteAverage = 0.0; for (int i = 0; i < numReadings; i++) { int readIndex = (writeIndex + bufferSize - numReadings + i) % bufferSize; tenMinuteAverage += buffer[readIndex]; } tenMinuteAverage /= numReadings; Serial.print("10-minute average: "); Serial.print(tenMinuteAverage); Serial.println(" °C"); // Print the highest value, lowest value, and overall average Serial.print("Highest value: "); Serial.print(highestValue); Serial.println(" °C"); Serial.print("Lowest value: "); Serial.print(lowestValue); Serial.println(" °C"); Serial.print("Overall average: "); Serial.print(overallAverage); Serial.println(" °C"); // Reset the previous interval time previousIntervalTime = currentTime; } // Print the stored temperature readings Serial.println("Stored temperature readings:"); for (int i = 0; i < numReadings; i++) { int readIndex = (writeIndex + bufferSize - numReadings + i) % bufferSize; Serial.print("Reading "); Serial.print(i + 1); Serial.print(": "); Serial.print(buffer[readIndex]); Serial.println(" °C"); } Serial.println(); // Check if the desired number of readings is reached if (numReadings >= bufferSize) { while (true) { // Stay in an infinite loop to prevent further execution } } delay(1000); // Delay between readings }