Arduino stops working after an unpredictable period of time

I am a Chemical Engineering Master student and currently working on a temperature controlled insulation box for doing experiments concerning crystallization.

The regulation i used consists of a 5VDC relay to switch a lamp (heat source) on an of depending on the measured temperature (TSYSO1 sensor). An LCD is mounted to print the setpoint and the actual measured temperature.

Both LCD and temperature sensor are connected via I2C to the Arduino. (ATMega328)

The problem I am currently facing is that after an undetermined period of time (5 minutes, 30 minutes, always different) the Arduino just stops working. When I press the reset button, it starts working again.

This is an unconfortable problem as I am willing to run the entire setup for several hours to ensure that it works propperly for my experiments.

Pleas help ! (See code below)

#include <Wire.h>
#include "TSYS01.h"
#include <LiquidCrystal_I2C.h>

TSYS01 sensor;
float desiredTempC = 30.00; // which temperature to maintain
int pinOut = 13; // setup output

// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {

Serial.begin(9600);

Serial.println("Starting");

Wire.begin();

sensor.init();

pinMode(13, OUTPUT); // sets the digital pin 13 as output

lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.begin (16,2); //Define the LCD as 16 column by 2 rows
lcd.setCursor (0,0); //Go to first column and first line
lcd.print("Setpoint = ");
lcd.setCursor(0,1); //Go to first column and second line
lcd.print("Actual Temp = ");

}

void loop() {

sensor.read();

Serial.print("Temperature: ");
Serial.print(sensor.temperature());
Serial.println(" deg C");

lcd.setCursor(12,0);
lcd.print(desiredTempC);

lcd.setCursor(12,1);
lcd.print(sensor.temperature());

delay(1000); //wait 1 second
if(sensor.temperature() < desiredTempC){
digitalWrite(pinOut, HIGH);
}
else{
digitalWrite(pinOut, LOW);
}

}

Windows may be turning off the USB port.

Even if I connect the usb cable with my phone charger and put it in the socket, the problem is repeating itself.

Niels132:
Even if I connect the usb cable with my phone charger and put it in the socket, the problem is repeating itself.

Break your code down into smaller pieces and see if the behavior repeats.

The code is simple enough :slight_smile:
How do you control the relay? Show a schematic or photo of you wiring

It’s quite possible that electrical noise generated when the relay operates is crashing the Arduino , and it’s random

The relay should have a “ flywheel” diode across the coil
to clamp the back emf .
Whatever you are switching should be on a power supply man enough for the task
Post your circuit up and what you are switching .

So i have placed an attachment with my circuit.
Looks a bit amateuristic, but I hope it will give the information needed

In the attachment, there is a picture of the circuit.
Note that in this picture, another temperature sensor is connected (LM35).
The wiring scheme I have drawn, is the one where the TSYS01 sensor is connected.

I have replaced the TSYSO1 sensor with the LM35 but the problem is still present.

Wiring scheme.doc (429 KB)

Is that a solid state relay or a regular relay ?

Also the suggestion about a diode is a very good one.

What is the specification for the relay as it might be drawing too much current from the Arduino causing the Arduino to reset on occasion.

A seperate PSU feed to the relay with a common ground might also fix it but again you would need to add protection to the relay to prevent spikes to the Arduino.

Check the Arduino can supply enough current to drive the relay- look at the Arduino spec ( can’t recall )
The relay coil needs a flywheel diode.
The wiring is not great and the temperature sensor wiring needs to be seperate from the power side , or use a screened cable.

Disconnect bits in turn to find the real source of the problem.

@hammy

"flywheel diode" That made my day...Thanks.