#include // Address for LM75 Temperature Sensor #define LM75_ADDR 0x48 // Interval between temperature readings (in milliseconds) const unsigned long interval = 1000; // Equal to 1 second unsigned long previousMillis = 0; float temperatureSum = 0.0; float highestTemperature = -273.15; // Absolute zero as the initial value float lowestTemperature = 1000.0; // high initial value int numReadings = 0; int numAverages = 0; float overallAverage = 0.0; bool printStatistics = false; void setup() { Serial.begin(115200); // Initialize I2C communication Wire.begin(); } void loop() { unsigned long currentMillis = millis(); // Check if it's time to read the temperature values if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; // Request temperature values from LM75 Wire.beginTransmission(LM75_ADDR); Wire.write(0x00); Wire.endTransmission(); // Read temperature data Wire.requestFrom(LM75_ADDR, 2); while (Wire.available() < 2) { } int16_t rawTemp = (Wire.read() << 8) | Wire.read(); // Convert raw temperature data from Celsius to Fahrenheit float temperatureCelsius = rawTemp / 256.0; float temperatureFahrenheit = (temperatureCelsius * 9 / 5) + 32; // Calculate temperature statistics temperatureSum += temperatureFahrenheit; numReadings++; numAverages++; if (temperatureFahrenheit > highestTemperature) { highestTemperature = temperatureFahrenheit; } if (temperatureFahrenheit < lowestTemperature) { lowestTemperature = temperatureFahrenheit; } // Print temperature data Serial.print("Temperature: "); Serial.print(temperatureFahrenheit); Serial.println(" F"); // Check if it's time to output the statistics if (currentMillis >= 10800000 && !printStatistics) { // 3 hours (3 * 60 * 60 * 1000) printStatistics = true; } // Check if it's time to print the statistics if (printStatistics) { // Calculate the overall average temperature overallAverage = temperatureSum / numReadings; // Print the statistics Serial.println("Printing statistics:"); Serial.print("10 Minute Average: "); Serial.print(overallAverage); Serial.println(" F"); Serial.print("Highest Temperature: "); Serial.print(highestTemperature); Serial.println(" F"); Serial.print("Lowest Temperature: "); Serial.print(lowestTemperature); Serial.println(" F"); Serial.print("Overall Average: "); Serial.print(overallAverage); Serial.println(" F"); Serial.println(); // End the program while (true) { // Do nothing } } } }