For this project, I've been trying to design a thermostat. I built a shield over my arduino uno that includes an adafruit temperature sensor and adafruit LED display. These are controlled through the serial pins TX and RX
The main issue is that the whole system seems to crash after just a few cycles. To test this, below is the code I used to try to isolate the issue. As it is written now, it should just blink the lights and display the cycle count on the display. I cut out a lot of superfluous stuff but a bunch is still there, albiet unused.
#include <Wire.h>
#include "Adafruit_MCP9808.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
// Create the Objects
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
//Temperature Variables
String Temp_s = ""; //Temperature String for Alpha4
int t = 0; //Temperature value for Control
int B = 0; //Brightness
int cycle_count =0;
//Button Location B INPUTS
const int b_red = 5; //red button in pin 5
const int b_wht = 6; //white button in pin 6
const int b_blu = 7; //blue button in pin 7
//Light Location L OUTPUTS
const int l_red = 4; //red light in pin 3
const int l_wht = 3; //white light in pin 2
const int l_blu = 2; //blue light in pin 1
//Value of Switch S Input Logic
int s_red = 0; // red button LOW
int s_wht = 0; // white button LOW
int s_blu = 0; // blue button LOW
//Value of Light K Output Logic
int k_red = 0; // red light LOW
int k_wht = 0; // white light LOW
int k_blu = 0; // blue light LOW
int k_LED = 1; // Alpha4 LEDs HIGH
//Countdown Variables
int countdown_tick_red = 0;
int countdown_tick_blu = 0;
int countdown_tick_LED = 0;
int countdown_limit_red = 5 * 6000; //number of minutes to keep button on
int countdown_limit_blu = 5 * 6000;
int countdown_limit_LED = 600;
void setup()
{
//Button pins are INPUT
pinMode(b_red, INPUT);
pinMode(b_wht, INPUT);
pinMode(b_blu, INPUT);
//Light pins are OUTPUT
pinMode(l_red, OUTPUT);
pinMode(l_wht, OUTPUT);
pinMode(l_blu, OUTPUT);
//Begin Serial devices
Serial.begin(9600);
alpha4.begin(0x70); // Begin Alpha4
alpha4.setBrightness(B);
//if (!tempsensor.begin()) //Begin Temp Sensor
//{ Serial.print("No Temp Sensor");
//while (1);
//}
}
void loop()
{
cycle_count= cycle_count+1;
if (cycle_count =9999)
{cycle_count =0;}
//Retrieve temperature Data
// float c = tempsensor.readTempC(); //C Celcius Data
// float f = c * 9.0 / 5.0 + 32; //f Farenhiet Data
Temp_s = String(cycle_count);
//Read/Write B,L
// Switch S reads Button B
s_red = digitalRead(b_red);
s_wht = digitalRead(b_wht);
s_blu = digitalRead(b_blu);
//Light K writes to Light L
digitalWrite(l_red, k_red);
digitalWrite(l_wht, k_wht);
digitalWrite(l_blu, k_blu);
//Alpha Display
if (k_LED == 1)
{
alpha4.writeDigitAscii(0, Temp_s[0]); //Temperature Reading
alpha4.writeDigitAscii(1, Temp_s[1]);
alpha4.writeDigitAscii(2, Temp_s[3]);
alpha4.writeDigitAscii(3, Temp_s[4]);
alpha4.writeDisplay();
}
//Button to Light logic
//Control Logic
// t = int(f + .5); //Temperature integer, rounded
//Serial Printing
Serial.println(cycle_count);
Serial.print("Temperature: ");
Serial.println(Temp_s);
//Serial.print(Ra);
// Serial.print(trigger_c);
//Serial.print("_");
//Serial.println(Ra_old);
k_red=!k_red;
delay(50);
k_wht=!k_wht;
delay(50);
k_blu=!k_blu;
// Ra_old = Ra;
delay(500);
//Needs timer. Library? Custom code? Test array function.Sketch out control scheme
}
At first I thought it might be overheating, as the enclosure could use some air holes. But after running it with a fan over it, the issue persists.
The worst part is that for some reason I cant restart the arduino unless I leave it unplugged for a few minutes. This issue persists across both arduinos I have on hand.
When I cut out the serial devices, the lights blink all night. But with either of them, I never get more than 2 minutes of function.
Any help would be appreciated.
(Not sure if this question is on the right board, it's kinda unclear)

