Thermostat Arduino crashes, serial devices

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)

This is probable as good a place as any to begin. But you need to identify which Arduino you are using and provide a schematic drawing showing how you have everything connected.

Your description leads me to the voltage regulator on the Arduino overheating and needing time to cool and reset. Or there is a self resetting fuse somewhere that takes quite a long time to reset. The above request for information is critical if you don't want to spend days arguing on the forum!

Paul

Hi,
Welcome to the forum.

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

Why are you using the pins that are used to program the controller, how many I/O are you using?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Thanks guys,

I'm using an arduino UNO. Below is a picture of the shield. Red wires are 5v, black is ground, the rest are signals. As you can see, I operate the temp sensor, LED display, and a rheostat off of the same 5v source. The triacs act as switches and isolation from the main AC.

I'm using the serial ports because the temperature sensor and LED display operate off of them.
Temperature Sensor doc sheet
LED Display doc

Hi,
Thanks for the image.
Your "serial" is I2C comms using A4 and A5.
Where is your display, what sort is it?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Is see a LED you have in series with the input of each opto, but where is the current limit resistor?

Thanks.. Tom... :slight_smile:

The display is the .54" Alphanumeric display, I believe it's page 21 on the documentation

Thanks for reminding me about the I2C comm. Those are what control the devices.

Below is a drawing of the relevant circuit. It's not a very sophisticated circuit.

Hi,
You will need to calculate some current limit resistors for your triac LEDs.

LED in Opto-Triac from 3021 datasheet 1.15V drop.
Externa LED is 1.6V drop.

1.15 + 1.6 = 2.75V. Total drop.

3021 datasheet says 15mA trigger current.

Series Resistor = 2.75/0.015 = 183R or 180R standard value.

Tom.. :slight_smile:

Hi,

Tom... :slight_smile:

Why is that? The triacs have been working fine.

TGGeko:
Why is that? The triacs have been working fine.

Without the resistors, the outputs of the UNO will be trying to supply more than the current they are rated at.
This may be causing your code to crash as you are causing a supply overload and UNO output component stress.
Please try the resistors.

Tom.... :slight_smile:

Tom, I've implemented your solution. The triacs all have current limiting resistors. The issue still persists.

I've also tried moving the devices to the 3.3V source, I've also tried a brand new arduino uno board. The issue still persists.

Do count the number of LEDs that are on in your LED display. It can easily be about 20 of them - even at a modest 10 mA per LED (I can't find the actual number in the document you linked to) you're drawing 200 mA from your 5V pin. Add to that the three TRIACs at 15 mA each plus what the other sensor draws and the needs of the Arduino itself and you are at 300 mA.

You didn't specify how your Arduino is powered, I assume it's not through the USB, so it's from an external power source. If that's a common 12V power supply your sweet little regulator has to dissipate 2.1W. No chance. Even at a rather minimal 7V supply it's 600 mA. That's enough to cause your regulator to overheat and shut down.

The solution to this: use an external 5V supply, which can power the Arduino (5V pin, not Vin which is the regulator) and your own board separately.

Counting each individual LED on the display, they add up to over 50.

I've used a few different things to power it, each with the same results. A 9 v battery, an AC to 9v adapter, and the USB cord.

I'll look into ways to reduce the input power, but I'm confused by what you said about the 5v pin. How is power supposed to reach the arduino if not through the Vin? How does the 5v act as a power input and output?

Finally, have I permanently damaged my arduino boards? Has the power regulator been damaged?

Hi,

TGGeko:
Counting each individual LED on the display, they add up to over 50.

I've used a few different things to power it, each with the same results. A 9 v battery, an AC to 9v adapter, and the USB cord.

I'll look into ways to reduce the input power, but I'm confused by what you said about the 5v pin. How is power supposed to reach the arduino if not through the Vin? How does the 5v act as a power input and output?

Finally, have I permanently damaged my arduino boards? Has the power regulator been damaged?

50 LEDs, are these the Triac Load?

Where are they on your circuit diagram?
Please give us a full diagram, take you time in doing it, it is an important part of your project.

Please post a picture of your COMPLETE project.

The 5V pin is not made to supply a lot of current, I stick to Input devices and small output loads such as LCD displays.
Do you have a DMM?

Tom, I've implemented your solution. The buttons all have current limiting resistors. The issue still persists

What buttons?
I referred to the output of the UNO and the input of the OPTO-COUPLE IC.
See R1, R2, R3 in my CAD diagram. If you add the extra LED as well you may need to drop the value of the resistors to 120R.

Tom.... :slight_smile:

TGGeko:
Counting each individual LED on the display, they add up to over 50.

What matters is how many of those are ON. That are the ones that draw power.

I'll look into ways to reduce the input power, but I'm confused by what you said about the 5v pin. How is power supposed to reach the arduino if not through the Vin? How does the 5v act as a power input and output?

5V pin is for a 5V supply. Simply the same net as the output of the regulator.
Vin is for >6.5V as it goes through the 5V regulator.
The USB connector should also bypass the regulator, not sure how that one is wired exactly.

Hi,

The USB connector should also bypass the regulator, not sure how that one is wired exactly.

The UNO could have a polyswitch, hence the cool down time needed to get the UNO to power up again.

Tom... :slight_smile: