#define SERIESRESISTOR 10000 #define NOMINAL_RESISTANCE 10000 #define NOMINAL_TEMPERATURE 25 #define BCOEFFICIENT 4300 unsigned int last10mins[600]; //sensor info every 1 sec for 10 min float avgMin[144]; //avg of each 10 min interval int tenIndex = 0; int fullIndex = 0; unsigned int minimum = 9999999999; unsigned int maximum = 0; unsigned long rollingSum = 0; // This assumes that the tempurature will never go below 0 F float rollingAvg; unsigned long myTime = 0; int endSeconds = 87000;//24 hours of seconds (modified) int analogPin = 35; float val= 0.0; float resistance = 0.0; float steinhart = 0.0; float avgdata(){ int sum = 0; for(int i = 0; i < 600; i++){ sum += last10mins[i]; } return ((float)sum)/600.0; } float voltToF(float volt){//Converting the analogvoltage to Celsius then to Fahrenheit 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(){//avgs at each 10 min interval, maximum, minimum, and overall average Serial.println("10 min intervals, sensor data"); //Titles for(int i = 0; i < fullIndex; i++){ Serial.print((i+1)*10); Serial.print(" mins, avg temp(F): "); Serial.println(voltToF(avgMin[i]));//must be converted } Serial.print("Average overall(F): "); Serial.println(voltToF(rollingAvg));//must be converted Serial.print("Minimum overall(F): "); Serial.println(voltToF((float)minimum));//must be converted as a float Serial.print("Maximum overall(F): "); Serial.println(voltToF((float)maximum));//must be converted as a float } void setup() { // put your setup code here, to run once: Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: if(myTime < endSeconds || fullIndex >= 144){//effectively ends the loops once it hits 24 hours myTime = (millis()-12)/1000; val = analogRead(analogPin); //prints the live data with time stamps Serial.print("Time running(sec): "); Serial.print(myTime); Serial.print(", Temp(F): "); Serial.println(voltToF(val)); //creation of the 10 min avgs array, simultaneously updates other data if(tenIndex < 600){ last10mins[tenIndex] = val; if(last10mins[tenIndex] < minimum) minimum = last10mins[tenIndex]; if(last10mins[tenIndex] > maximum) maximum = last10mins[tenIndex]; rollingSum += last10mins[tenIndex]; rollingAvg = (float)rollingSum / (float)(600*fullIndex+tenIndex); tenIndex++; } else { tenIndex = 0; avgMin[fullIndex] = avgdata(); fullIndex++; } } //this is just used to call for the data sheet char serinput; if (Serial.available()){ serinput = Serial.read(); if((char)serinput >= 32 && (char)serinput <= 126){ printData(); // printing what is in the 144 array (stats included overall maximum, minimum, average temp) } } delay(1000); }