// Ohm Thakor ENGR 103 Temperature Sensor 24 Hours Spring 2023 #include short ten_minute = 0, value, i = 0, c = 0, high = -300, low = 300; // ten_minute keeps sum of temps over 10 min, value stores the current temp, short ten_average[144]; // it is 144 because there are 6 10 minute increments per hour and 144 increments in 24 hours int total = 0, count = 0; //measures sum of all temps measured from time program starts LM75A lm75a_sensor(false,false,false); int ten (int i, short ten_minute, short ten_average[], int count) { if(count%600 == 0) //the number of values measured in 10 minutes { ten_average[i] = ten_minute/600; i++; ten_minute = 0; //ten_minute is reset back to 0. } return i; } void overall (int count, short ten_average[], int total, short high, short low) { Serial.println("Average Every 10 minutes in Celsius: "); for(i = 0; i < count/600; i++) { Serial.println(ten_average[i]); } Serial.println(); Serial.print("High: "); Serial.print(high); Serial.println(" °C"); Serial.print("Low: "); Serial.print(low); Serial.println(" °C"); Serial.println(); Serial.print("Overall Average: "); //running average Serial.print(total/count); Serial.println(" °C"); } void setup() { Serial.begin(115200); delay(500); Serial.println("Starting Program (Press r to generate a report):"); } void loop() { // put your main code here, to run repeatedly: value = lm75a_sensor.getTemperatureInDegrees(); //this is how temperature data is received from sensor if(value > high) { high = value; // this will set any new value to the highest value if it is greater than the previous highest value } if(value < low) { low = value; // this will set any new value to the lowest value if it is less than the current lowest value } Serial.print("Temperature: "); Serial.print(value); // current temperature Serial.println(" °C"); ten_minute += value; total += value; count++; // this measues the number of total measurements i = ten(i, ten_minute, ten_average, count); // will occur every ten minutes if(count%600 == 0) { ten_minute = 0; //ten_minute is reset back to 0. } if(Serial.available() > 0) { if(Serial.read() == 'r'); overall(count, ten_average, total, high, low); // these are the values shown at the end of program } delay(1); // this ensures that at least one millisecond has passed while(millis()%1000 != 0); // stops the code so there is a measurement every second. This accounts for lost time it takes to print previous value. while(count == 86400) //holds the code for exactly 24 hours (86400 seconds) { if(c == 0) { Serial.println(); Serial.println("24 hours have passed, no more temperatures will be measured and tracked"); Serial.println("Press r to print report"); c++; } if (Serial.available() > 0) { if(Serial.read() == 'r'); overall(count, ten_average, total, high, low); // these are the values shown once 'r' is entered } } }