const int thermistorPin = 35; // Instantiate pin 35 as the thermistor pin const unsigned long samplingInterval = 30000; // 30 seconds const unsigned long summaryInterval = 600000; // 10 minutes const unsigned long duration = 86400000; unsigned long previousSamplingTime = 0; unsigned long previousSummaryTime = 0; float highestTemperature = -273.15; // Initialize to lowest possible value float lowestTemperature = 100.0; // Initialize to highest possible value int totalReading = 0; int readingsCount = 0; float tenMinAverages[144]; int currentTenMinIndex = 0; void setup() { Serial.begin(19200); } void loop() { unsigned long currentMillis = millis(); // Read temperature every sampling interval if (currentMillis - previousSamplingTime >= samplingInterval) { previousSamplingTime = currentMillis; int sensorValue = readAnalogValue(thermistorPin); // Read analog value from pin 35 totalReading += sensorValue; readingsCount++; Serial.print("reading: "); Serial.println(sensorValue); Serial.print("total reading: "); Serial.println(totalReading); Serial.print("reading counts: "); Serial.println(readingsCount); Serial.print("time elapsed since start of program: "); Serial.println(currentMillis/1000); Serial.println("------------------"); // Update highest and lowest temperatures if (sensorValue > highestTemperature) { highestTemperature = sensorValue; } if (sensorValue < lowestTemperature) { lowestTemperature = sensorValue; } // Print temperature every summary interval if (currentMillis - previousSummaryTime >= summaryInterval) { previousSummaryTime = currentMillis; float averageTemp = float(totalReading) / readingsCount; // Add 10-minute average to the array tenMinAverages[currentTenMinIndex] = averageTemp; currentTenMinIndex++; // Print summary to serial monitor printSummary(highestTemperature, lowestTemperature, averageTemp); // Reset variables for next summary interval highestTemperature = -273.15; // Reset highest temperature to lowest possible value lowestTemperature = 100.0; // Reset lowest temperature to highest possible value totalReading = 0; readingsCount = 0; } } // Check if duration has elapsed if (currentMillis >= duration) { // Convert overall average to Celsius float overallAverage = float(totalReading) / readingsCount; // Print overall average temperature printSummary(highestTemperature, lowestTemperature, overallAverage); while (true) { // Infinite loop to halt further execution } } delay(samplingInterval); } // Time function unsigned long getTime() { static unsigned long startTime = 0; unsigned long currentTime = millis(); if (startTime == 0) { // Initialize the start time on the first function call startTime = currentTime; } // Calculate and return the elapsed time in milliseconds return currentTime - startTime; } int readAnalogValue(int pin) { pinMode(pin, INPUT); int reading = analogRead(pin); return reading; } // Print the summary void printSummary(float highestTemp, float lowestTemp, float overallAverage) { Serial.println("----- Temperature Summary -----"); Serial.print("Highest temperature recorded: "); Serial.println(highestTemp); Serial.print("Lowest temperature recorded: "); Serial.println(lowestTemp); Serial.print("Overall average temperature: "); Serial.println(overallAverage); Serial.println("------------------------------"); }