//declare pins int inputPin = 39; String input; //declare variables for calculation float mVIn=0; int currentTemp; float tenAVG; float averageTemp; //set max to 0 initially and min to be large int maxTemp = 0; int minTemp = 100000; float resistance; //declare counting index unsigned long i = 0; unsigned long x = 0; int minuteIndex = 0; //declare an array to store the last ten mins of temp. float lastTenMins[600]; float lastTenAvg; //converts mV to resistance float mVToRes(float mV) { float volts = mV / 1000; float res = ((10000*volts)/(5-volts)); return res; } //converts resistance to Degrees F int resToTemp(float res) { float ratio = res / 10000; int temp; if (0 < ratio < 0.055) { temp = 100; } else if (0.0553.2) { temp = 0; } int f = ((temp * (1.8)) + 49); return f; } //converts the current temp, total measurements, and avg. to the new avg. float tempToAvg(unsigned long j, unsigned long z, float temp, float avg) { unsigned long sum = avg * ((z*600) + j); float newAvg = ((sum + temp)/((z*600)+j+1)); return newAvg; } //prints out the Summary information void printSummary(float Max, float Min, float Avg, int current, float lastTenAverage, int seconds) { Serial.print("\n\n\n\n\n"); Serial.println("SUMMARY\n"); Serial.println("Time Since Program Initiation: "); Serial.print(seconds); Serial.println(" seconds"); Serial.println("Average Temperature(F): "); Serial.println(Avg); Serial.println("Temperature Range: "); Serial.print(Min); Serial.print(" to "); Serial.println(Max); Serial.println("Last Ten Minutes Average Temperature(F): "); Serial.println(lastTenAverage); Serial.println("Current Temperature(F): "); Serial.println(current); Serial.print("\n\n\n\n\n"); } //initialize pins and declare inputs/outputs void setup() { Serial.begin(115200); pinMode(inputPin, INPUT); for (int x = 0; x<600; x++) { lastTenMins[x] = 0; } } void loop() { //read the input pin mVIn = analogRead(inputPin); //calculate the resistance resistance = mVToRes(mVIn); //calculate the current temperature currentTemp = resToTemp(resistance); minuteIndex = i; lastTenMins[minuteIndex] = currentTemp; //Calculate Max and Min temperature if (currentTemp > maxTemp) { maxTemp = currentTemp; } if (currentTemp < minTemp) { minTemp = currentTemp; } //Calculate new running average averageTemp = tempToAvg(i, x, currentTemp, averageTemp); //Calculate last 10 mins average unsigned long sumTenMins = 0; for (int x = 0; x<600; x++) { sumTenMins = sumTenMins + lastTenMins[x]; } float summ = sumTenMins; lastTenAvg = (summ/600); //calculate seconds since startup unsigned long mill = millis(); unsigned long seconds = mill / 1000; //print data if (Serial.available()) { input = Serial.readStringUntil('\n'); input.trim(); if (input.equals("Summary") || input.equals("summary")){ printSummary(maxTemp, minTemp, averageTemp, currentTemp, lastTenAvg, seconds); }} else { Serial.print("Current Temperature(F): "); Serial.println(currentTemp); } //increment the seconds counter if (i == 599) { i = 0; x = x+1; } else { i = i + 1; } delay(1000); }