const int thermistorPin = 2; const double baseResist = 10000.0; const double baseTemp = 25.0; const double resistTempCoefficientB = 3950.0; const double seriesResistor = 10000.0; const unsigned long timerDuration = 240 * 60 * 1000; // 24 hours const unsigned long calcAverageTiming = 10 * 60 * 1000; // 10 minutes unsigned long startTime; //set integers, floats, etc unsigned long lastAverageCalc; unsigned long lastTempCheck; unsigned long currentTime; unsigned long passedTime; int tempDataArray[240 * 60]; //1 data point per 24 hrs int numOfData = 0; void setup() { Serial.begin(38400); startTime = millis(); lastAverageCalc = startTime; lastTempCheck = startTime; // set times to match } // gather averages of data for set period double calcCurrentAvg() { double allData = 0; int numSamples = numOfData; if (numSamples > calcAverageTiming / 1000) { numSamples = calcAverageTiming / 1000;//determine number of samples } //add data to allData for (int i = 0; i < numSamples; ++i) { allData += tempDataArray[numOfData - 1 - i]; } //determine the average temp for all data. double average = allData / numSamples; return average; } void loop() { currentTime = millis(); passedTime = currentTime - startTime; //end loop if (passedTime >= timerDuration) { return; } //this determines when to print the 10 minute average if (currentTime - lastAverageCalc >= calcAverageTiming) { double rollingAvg = calcCurrentAvg(); Serial.println("10 min average: "); Serial.println(rollingAvg); lastAverageCalc = currentTime; } if (currentTime - lastTempCheck >= 1000 && numOfData < (timerDuration / 1000)) { //gather data per second int rawValue = analogRead(thermistorPin); double resistance = seriesResistor * (4095.0 / rawValue - 1.0); //calc temperature with steinhart equation double resistTempCalc; resistTempCalc = resistance / baseResist; resistTempCalc = log(resistTempCalc); resistTempCalc /= resistTempCoefficientB; resistTempCalc += 1.0 / (baseTemp + 273.15); resistTempCalc = 1.0 / resistTempCalc; resistTempCalc = resistTempCalc - 273.15; resistTempCalc = resistTempCalc * 1.80; double temperature = resistTempCalc + 30.0; tempDataArray[numOfData] = temperature; ++numOfData; Serial.println(temperature); lastTempCheck = currentTime; } }