int pin = 34; double tempF; float R1 = 10000; float c1 = 3.354016e-03, c2 = 2.569850e-04, c3 = 2.620131e-06; double totalTen; //last ten minutes of temperatures added together double averageTen = 0; //average of the last ten minutes double highest = 0; //holds highest temperature double lowest = 100; //holds lowest temperature int tenCount; //holds count of each time total ten is added double total; //holds all of the temperatures double averageTotal; //holds the average of all the temperatures int count; //holds count of each time total is added //takes the voltage and returns the temperature in Fahrenheit double convert(double voltage) { double R2 = R1 * (1023.0 / voltage - 1.0); double logR2 = log(R2); double temp = 1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2); temp = temp - 273.15; temp = (temp * 9.0) / 5.0 + 32.0; return temp + 408; } //takes the Fahrenheit and prints it nicely void printTemp(double TEMP) { Serial.print("Fahrenheit is :"); Serial.println(tempF); } //adds the last ten minute teperature and stores it in totalTen variable //also adds one to the count each time a temperature is added to totalTen void addLastTen(double TEMP) { totalTen += TEMP; tenCount ++; } //calculate the ten minute average and saves it in averageTen variable void lastTen(double TOTAL, int COUNT) { averageTen = TOTAL / COUNT; } //finds highest temperature and stores it in highest //also finds lowest temperature and stores it in lowest void highLow(double TEMP) { if(TEMP > highest) { highest = TEMP; } if(TEMP < lowest) { lowest = TEMP; } } //prints the last ten minute average, the highest temperature so far, and the lowest temperature so far void printRequest(double AVERAGE, double HIGHEST, double LOWEST) { Serial.print("Average Temperature: "); Serial.println(AVERAGE); Serial.print("Highest Temperature: "); Serial.println(HIGHEST); Serial.print("Lowest Temperature: "); Serial.println(LOWEST); } //adds the all the temperatures and stores in total variable //also adds one to the count each time a temperature is added to temp void addTotal(double TEMP) { total += TEMP; count ++; } //takes the average of all the temperatures void average(double TOTAL, int COUNT) { averageTotal = TOTAL / COUNT; } //prints the average of all temperatures void printAverage(double TOTAL) { Serial.print("Average: "); Serial.println(TOTAL); } void setup() { // put your setup code here, to run once: Serial.begin(115200); delay(1000); Serial.println("Code Start"); } void loop() { // put your main code here, to run repeatedly: int rawTemp = analogRead(pin); double voltage = (rawTemp / 1023.0) * 5.0; tempF = convert(voltage); printTemp(tempF); addLastTen(tempF); addTotal(tempF); highLow(tempF); if(tenCount == 600) { lastTen(totalTen, tenCount); printRequest(averageTen, highest, lowest); totalTen = 0; tenCount = 0; } delay(1000); }