I’m just doing temperature control with 4 thermistor inputs and 4 digital outputs. The setpoints are adjustable via IOT Cloud. If the measured temperature drops 6.5°F below the setpoint the corresponding output is enabled, and disabled when the temperature rises 6.5°F above setpoint.
It seems like it’s working perfectly fine. But after a few days/weeks I’ll notice an output or two are remaining consistently off even though their corresponding temperature sensor is well below setpoint. After cycling power on the Arduino everything works perfectly fine again. How can I begin troubleshooting this? The debug console looks like it just repeats the COM port over and over. Thanks in advance.
#include "thingProperties.h"
#include <math.h>
float TempAvg1, TempAvg2, TempAvg3, TempAvg4;
byte a(0);
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0/(1024.0/RawADC-1)); // for pull-up configuration
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
Temp = (Temp * 9.0)/ 5.0 + 32.0; //°C to °F
return Temp;
}
void setup() {
setDebugMessageLevel(4);
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
ArduinoCloud.update();
a = 0;
TempAvg1 = 0;
while(a < 25) {
TempAvg1 = TempAvg1 + (float(Thermistor(analogRead(A1))));
a = a + 1;
}
TempAvg1 = TempAvg1 / 25;
TempAvg2 = 0;
while(24 < a && a < 50) {
TempAvg2 = TempAvg2 + (float(Thermistor(analogRead(A2))));
a = a + 1;
}
TempAvg2 = TempAvg2 / 25;
TempAvg3 = 0;
while(49 < a && a < 75) {
TempAvg3 = TempAvg3 + (float(Thermistor(analogRead(A3))));
a = a + 1;
}
TempAvg3 = TempAvg3 / 25;
TempAvg4 = 0;
while(74 < a && a < 100) {
TempAvg4 = TempAvg4 + (float(Thermistor(analogRead(A4))));
a = a + 1;
}
TempAvg4 = TempAvg4 / 25;
if (TempAvg1 > (Floor_1 + 6.5)) digitalWrite(0, LOW);
if (TempAvg1 < (Floor_1 - 6.5)) digitalWrite(0, HIGH);
if (TempAvg2 > (Floor_2 + 6.5)) digitalWrite(1, LOW);
if (TempAvg2 < (Floor_2 - 6.5)) digitalWrite(1, HIGH);
if (TempAvg3 > (Floor_3 + 6.5)) digitalWrite(2, LOW);
if (TempAvg3 < (Floor_3 - 6.5)) digitalWrite(2, HIGH);
if (TempAvg4 > (Floor_4 + 6.5)) digitalWrite(3, LOW);
if (TempAvg4 < (Floor_4 - 6.5)) digitalWrite(3, HIGH);
}
void onFloor1Change() {
// Do something
}
void onFloor2Change() {
// Do something
}
void onFloor3Change() {
// Do something
}
void onFloor4Change() {
// Do something
}