#include DHT dht(15, DHT22); unsigned long startTime; // Keep track of time (start) unsigned long elapsedTime; // Keep track of time (end) const unsigned long measurementInterval = 1000; // Measurement interval in milliseconds -- 1 second const unsigned long measurementDuration = 3 * 60 * 60 * 1000; // Measurement duration in milliseconds (3 hours) float temperatureSum = 0; // Takes sum of all temperature readings float highestTemperature = -1000; float lowestTemperature = 1000; int measurementCount = 0; // Keeps track of the number of measurements taken void setup() { Serial.begin(115200); // Initialize the serial communication dht.begin(); startTime = millis(); // startTime variable initiated } void loop() { elapsedTime = millis() - startTime; // Current time subtracting startTime if (elapsedTime >= measurementInterval) { float temperatureC = dht.readTemperature(); // Read temperature in Celsius if (isnan(temperatureC)) { //checks if the temperature value is not a number (NaN) -- Error Serial.println("Failed to read temperature from DHT sensor!"); } else { float temperatureF = temperatureC * 1.8 + 32; // Convert Celsius to Fahrenheit temperatureSum += temperatureF; measurementCount++; if (temperatureF > highestTemperature) { //Checks if value is higher -- if it is, updated highestTemperature = temperatureF; } if (temperatureF < lowestTemperature) { // Checks if value is lower -- if it is, updated lowestTemperature = temperatureF; } Serial.print("Temperature: "); Serial.print(temperatureF); Serial.println(" °F"); } startTime = millis(); } if (elapsedTime >= measurementDuration) { printReport(); while (true) { // Infinite loop to stop further execution -- calls upon printReport once exceeding 3 hours } } delay(100); // Delay between readings } void printReport() { Serial.println(); Serial.println("----- Report -----"); Serial.println("Average Every 10 minutes in Fahrenheit: "); float averageTemperature = temperatureSum / measurementCount; Serial.println(averageTemperature); Serial.print("Highest Temperature: "); Serial.print(highestTemperature); Serial.println(" °F"); Serial.print("Lowest Temperature: "); Serial.print(lowestTemperature); Serial.println(" °F"); Serial.println(); Serial.print("Overall Average: "); Serial.print(averageTemperature); Serial.println(" °F"); Serial.println("------------------"); Serial.println(); }