/* Paviat Rai * ENGR 103 * FINAL PROJECT * 7 July 2023 */ // Do not mind all the variables. They have all been acounted for and were taking up too much room vertically so I put a lot of them in one line int ThermistorPin = 36;int Vo; float R1 = 10000;float R2;float STH;float T;float F;float A = 1.009249522e-03;float B = 2.378405444e-04;float C = 2.019202697e-07;float High = -1000;float Low = 1000;float TENARRAY[600];float tentempsum = 0;float tenminav = 0;float tempsum = 0; int millipassed = 0; float milliten = 0;float totalav = 0;float ARRAYOFTEN[144]; unsigned long startTime; int extratime = 0;int ind = 0;int x = 0; float Temperature(){ // Steinhart-Hart equation stuff Vo = analogRead(ThermistorPin); R2 = R1 * (4096.0 / (float)Vo - 1.0); STH = log(R2); T = (1.0 / (A + B*STH + C*STH*STH*STH)); T = T - 273.15; T = (T * 9.0)/ 5.0 + 32.0; return T; } void REPORT(){ // function for 10 min reports if (Serial.available() > 0){ // checks serial port String userInput = Serial.readString(); // reads input userInput.trim(); // gets rid of extra stuff if (userInput.equalsIgnoreCase("report")){ if(x == 0){ Serial.println("The program has not been reading temperatures for 10 minutes."); } else{ Serial.println("All of the ten minute averages will now be printed."); for(int o = 0; o < x; o++){ Serial.print(ARRAYOFTEN[o]); Serial.println(" F"); tentempsum = 0; tenminav = 0; } delay(10000); Serial.println("The highest, lowest, and total average temperatures since the program started will now be displayed"); Serial.print("Highest temperature: "); Serial.print(High); Serial.println(" F"); Serial.print("Lowest temperature: "); Serial.print(Low); Serial.println(" F"); Serial.print("Total average temperature: "); Serial.print(totalav); Serial.println(" F"); extratime +=10000; } extratime +=10000; delay(10000); } } } void PRINTING(){ // simply prints every second Serial.print("Temperature: "); Serial.print(F); Serial.println(" F"); } void setup() { Serial.begin(115200); startTime = millis(); // time that may interfere with accurate results } void loop() { delay (1000); // it has to being with a delay to avoid starting at 0 milliseconds millipassed = millis() - extratime - startTime; // total time since the loop has started subtracting extra time milliten = (millipassed/1000) % 600; // Counts the seconds in each 10 min interval F = Temperature(); // calling function TENARRAY[ind] = F; // array of temps in 10 mins ind = (ind + 1) % 600; // resets index after 10 mins if (millipassed >= 600000){ // starts the 10 min averaging if (milliten == 0){ tentempsum = 0; for (int i = 0; i < 600; i++){ // adds all values and finds 10 min av tentempsum = TENARRAY[i] + tentempsum; } tenminav = tentempsum / 600.0; ARRAYOFTEN[x] = tenminav; x++; } } tempsum += F; // is what it sounds like totalav = tempsum / (millipassed/1000); // total avs if (F > High){ // highest and lowest temps High = F; } if (F < Low){ Low = F; } REPORT(); PRINTING(); }