/* Conor Holloway ENGR 103 - Final Project Code Temperature Sensor Data Collection (24 Hours) Below is a program designed to collect the temperature of a room every second for 24 hours. The data is collected and processed into 10 minute averages which are then stored in an array for later reporting. At any time the user can enter 'r' into the message box on the Serial Moniter to print the report of the data collected so far. At the end of the 24 hours the program waits indefinitely for the user to print the final report. I used a library from RoboJax, this allows us to access the temperature from the LM75A https://github.com/QuentinCG/Arduino-LM75A-Temperature-Sensor-Library */ #include short tenMin = 0, temp, i = 0, c = 0, high = -100, low = 100; short tenAve[144]; // 6 (10 minute increments) * 24 (hours) int count = 0, total = 0; LM75A lm75a_sensor(false, false, false); int average (int i , short tenMin, short tenAve[], int count) { if (count % 600 == 0) { tenAve[i] = tenMin / 600; i++; tenMin = 0; } return(i); } void report (int count, int total, short high, short low, short tenAve[] ) { Serial.println("Averages the temperature in 10 minute periods (Celcius)"); for (int i = 0 ; i < count/600; i++) { // Prints the 144 averages spaced apart (i < 1 + count/600 because without the +1 any i < 1 would read as 0. 0 !< 0) Serial.print("Average ("); Serial.print(i + 1); Serial.print("):"); Serial.println(tenAve[i]); } // Prints the highest, lowest, and average of the 10 minute periods Serial.print("High: "); Serial.print(high); Serial.println(" °C"); Serial.print("Low: "); Serial.print(low); Serial.println(" °C"); Serial.print("Overall Average: "); Serial.print(total/count); Serial.println(" °C"); } void setup () { Serial.begin(115200); //BAUD Rate delay(100); Serial.println(); Serial.println("COMMENCING OPERATION: temp_sensor"); Serial.println(); //Serial.println("") } void loop () { temp = lm75a_sensor.getTemperatureInDegrees(); //Function from the LM75A.h library while (temp == 1000) { temp = lm75a_sensor.getTemperatureInDegrees(); //Replaces inaccuacy of 1000°C to new temp } if (temp > high) { //Collects the highest recorded temperature high = temp; } else if (temp < low) { //Collects the lowest recorded temperature low = temp; } Serial.print("Temperature ("); Serial.print(count + 1); //Prints the most recent collected temperature Serial.print("): "); Serial.print(temp); Serial.println(" °C"); tenMin = tenMin + temp; //Stores temp in one variable(s) for later use total = total + temp; count++; //Measures amount of temperatures collected i = average(i ,tenMin, tenAve, count); //Occurs every 10 minutes if (count % 600 == 0) { //clears tenMin variable, for later averages tenMin = 0; } //Prints report if (Serial.available() > 0) { //Checks to see if anything hads been input if (Serial.read() == 'r') { //Checks to see if input matches instruction report(count, total, high, low, tenAve); //Prints the report function, only if 24 hours has passed } } delay(1); //Insures 1 mS has passed before (failsafe for the while loop below) while(millis()%1000 !=0); //Puts into endless loop until a new second occurs, allows for 1 temperature collected per second while(count == 86400) { //Holds the loop at exactly 86400 seconds runtime (24 hours) if (c == 0) { Serial.println(); Serial.println("24 hours has passed, the data collection process will be terminated"); Serial.println("Please type 'r' to print the Temperature Report"); c++; } if (Serial.available() > 0) { //Checks to see if anything hads been input if (Serial.read() == 'r') { //Checks to see if input matches instruction report(count, total, high, low, tenAve); //Prints the report function, only if 24 hours has passed } } } }