#include int analogPin = 32; float val = 0.0; unsigned long myTime = 0; float highest= -1000.0;//Low number to start out with float lowest = 1000.0;//high number to start out with float temperatureReadings[200]; float tenMinAvg = 0.0; float overallAvg = 0.0; int totalTenMinReadings = 0; int tenMinCount = 0; int totalReadings = 0; unsigned long totalReadingsCount = 0; //Conversion function to Fahrenheit float fConvert(float boardReading) { //variable definitions for the constants float R1 = 10000; float logR2, R2, T; float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07; //Conversion begins here R2 = R1 * (4095.0 / (float)boardReading - 1.0); logR2 = log(R2); T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); T = T - 273.15; T = (T * 9.0)/ 5.0 + 32.0; return T; } //void getTenMinAvg(float thermistor), highestValues(float thermistor), lowestValues(float thermistor) //declare these functions below void printSummaries() { int i; Serial.printf("The highest reading was: %f F\n", highest); Serial.printf("The lowest reading was: %f F\n", lowest); Serial.printf("The overall average was: %f F\n", overallAvg); Serial.println("Ten minute average readings of this room are: "); for (int i = 0; i (myTime + 600000))//only true 10 minutes(600000 mS) after myTime { temperatureReadings[totalTenMinReadings] = tenMinAvg; Serial.printf("10 min value: %fF\n", tenMinAvg); tenMinAvg = 0.0; tenMinCount = 0; totalTenMinReadings++; myTime = millis(); } } void highestValue(float thermistor) { if(thermistor > highest) { //Serial.printf("new highest to be set %f old %f\n", thermistor, highest); highest = thermistor; } } void lowestValue(float thermistor) { if(thermistor < lowest) { //Serial.printf("new lowest to be set %f old %f\n", thermistor, lowest); lowest = thermistor; } } void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("Type y to see the summary reports"); } void loop() { // put your main code here, to run repeatedly: //variable declarations char summary; val = analogRead(analogPin); //convert the reading to degrees fahrenheit val = fConvert(val); //prevents infinate number as average first time through is the same as the currrent reading(val) if(totalReadingsCount == 0) { overallAvg = val; totalReadingsCount = 1; } else { //Serial.printf(" #1 Total reading: %ld Temp: %f Overall AVG: %f\n",totalReadingsCount, val, overallAvg); // debug: Serial.printf("Average: %f New reading: %f Iterations: %d\n", overallAvg, val, totalReadingsCount); totalReadingsCount++; overallAvg = (overallAvg*(totalReadingsCount-1)+val)/totalReadingsCount; //Serial.printf(" # 2Total reading: %ld Temp: %f Overall AVG: %f\n",totalReadingsCount, val, overallAvg); } //update min and max fucntions highestValue(val); lowestValue(val); //update average functions getTenMinAvg(val); //User input and what to do with it; when y or Y is entered summarys are given. if(Serial.available() > 0) { summary = Serial.read(); if(summary == 'y'|| summary == 'Y') { //Functions that print reports Serial.println("Got it"); printSummaries(); } } }