unsigned int last10[600]; //sensor info every second for 10 min float avgData[144]; //average of each 10 min interval int tenIndex = 0; int fullIndex = 0; unsigned int minimum = 99999999999; //Needs to be a very large number so that the minimum can update to something lower. unsigned int maximum = 0; //Same thing for maximum as minimum but the other way. unsigned long rollingSum = 0; //Temperature will never go below 0 F float rollingAverage; unsigned long myTime = 0; int endSeconds = 87000; //this is 24 hours in seconds + 10 minutes because it was not counting the last 10 minutes when it was set to 86400 int analogPin = 35; float val = 0; float Resistance = 0.0; float steinhart = 0.0; #define SERIESRESISTOR 10000 #define NOMINAL_RESISTANCE 10000 #define NOMINAL_TEMPERATURE 25 #define BCOEFFICIENT 4300 float avgdata() { int sum = 0; for(int i = 0; i < 600; i++) { sum += last10[i]; } return ((float)sum)/600.0; } float TempToF(float volt) //This function turns the analog voltage that we are given from the thermistor into temperature in Kelvin, then Celsius, then Fahrenheit and returns this value. { Resistance = (4095 / volt) - 1; Resistance = SERIESRESISTOR * Resistance; steinhart = Resistance / NOMINAL_RESISTANCE; steinhart = log(steinhart); steinhart /= BCOEFFICIENT; steinhart += 1.0 / (NOMINAL_TEMPERATURE + 273.15); steinhart = 1.0 / steinhart; steinhart -= 273.15; steinhart = steinhart *(9.0/5.0) + 32.0; return steinhart; } void printData() //This is what allows us to see all of the required data for the project. { Serial.println("10 min intervals, sensor data"); //Titles for (int i = 0; i < fullIndex; i++) { Serial.print((i+1)*10); Serial.print(" mins, "); Serial.println(TempToF(avgData[i])); } Serial.print("Average so far: "); Serial.println(TempToF(rollingAverage)); Serial.print("Minimum so far: "); Serial.println(TempToF((float)minimum)); Serial.print("Maximum so far: "); Serial.println(TempToF((float)maximum)); } void setup() { // put your setup code here, to run once: Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: char serinput; if(myTime < endSeconds || fullIndex >=144) //This makes it so that if the the time hits endSeconds or fullIndex >=144, then the serial moniter will stop adding values to the output. { myTime = (millis()-12)/1000; //The time started at 12 milliseconds, so I subtracted by 12, then converted the milliseconds into seconds. val = analogRead(analogPin); Serial.print("Temperature "); Serial.print(TempToF(val)); Serial.println(" F"); Serial.print("Time passed (seconds): "); //Prints the time that has passed since starting in seconds Serial.println(myTime); if (tenIndex < 600) //This makes it so that anything less than the minimum would become the new minimum and anything greater than the maximum would become the new maximum. { last10[tenIndex] = val; if (last10[tenIndex] < minimum) minimum = last10[tenIndex]; if (last10[tenIndex] > maximum) maximum = last10[tenIndex]; rollingSum += last10[tenIndex]; rollingAverage = (float)rollingSum / (float)(600*fullIndex + tenIndex); tenIndex++; } else { tenIndex = 0; avgData[fullIndex] = avgdata(); fullIndex++; } } if (Serial.available()) //prints the data when any character is input { serinput = Serial.read(); if ((char)serinput >= 32 && (char) serinput <= 126) { printData(); } } delay(1000); //Delays the whole program by 1 second everytime it runs so that we only get the temperature every second. }