Arduino Freezes After 5-10 Minutes of Operation, Arduino Stops Functioning - Need Assistance

Hello everyone, I would like to start by stating that I am at a beginner level in Arduino. I have prepared an Arduino project as described below. However, when the circuit is operational, I encounter a specific issue. It works smoothly for about 5-10 minutes, but afterward, the I2C screen freezes, and the Arduino stops functioning (the heater and ventilator keep running continuously). When I manually turn off the heater, the Arduino resumes functioning without any issues. Despite trying to connect a resistor with different values to the signal (+) pin of the solid-state relay that controls the heater and externally powering the I2C module with 5V, I have not been able to find a solution. What can I do about this? Thank you for your help.

Here is my Arduino code;

#include <LiquidCrystal_I2C_AvrI2C.h>
#include <AvrI2c_Greiman.h>
#include <Wire.h>
#include <Arduino.h>
#include "MHZ19.h"                                        
#include <SoftwareSerial.h>                                 
#include "SparkFunHTU21D.h"
HTU21D myHumidity;


#define RX_PIN 12                                          // Rx pin which the MHZ19 Tx pin is attached to
#define TX_PIN 11                                         // Tx pin which the MHZ19 Rx pin is attached to
#define BAUDRATE 9600                      

MHZ19 myMHZ19;                                      
SoftwareSerial mySerial(RX_PIN, TX_PIN);                   
unsigned long getDataTimer = 0;

  
int relay1=5;              // Heater relay
int relay2=3;              // Floresans relay
int relay3=8;              // Aspirator relay
int LDRPin = A0;		


void setup()
{
    
    lcd.begin();              
    Serial.begin(9600);                                     
    myHumidity.begin();
    mySerial.begin(BAUDRATE);                               
    myMHZ19.begin(mySerial);                                
    myMHZ19.autoCalibration(false);                             

    pinMode (role1, OUTPUT);
    pinMode (role2, OUTPUT);
    pinMode (role3, OUTPUT);
    
}

void loop()
{

    float humd = myHumidity.readHumidity();
    float temp = myHumidity.readTemperature();

lcd.setCursor(0,0); 
lcd.print("Temp: "); lcd.print(temp, 1); lcd.print(" C"); 
lcd.setCursor(0,1); 
lcd.print("Humd: "); lcd.print(humd, 2);  lcd.print(" %"); 
delay(10000);
lcd.clear();
    

    int  CO2 = myMHZ19.getCO2();

    CO2 = myMHZ19.getCO2();                             
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("CO2(ppm):");
      lcd.setCursor(0,1);                     
      lcd.println(CO2);  
      delay(10000);
      lcd.clear();

       int lighting value = analogRead(LDRPin);

// Relay connections

// Aspirator relay
if (CO2 >= 700)
{
  digitalWrite(relay3, LOW);

}

if (CO2 <= 600)
{
  digitalWrite(relay3, HIGH);
} 

// HTU21D relay
if (temp <= 19)
{
  digitalWrite(relay1, HIGH);
}

if (temp >= 22)
{
  digitalWrite(relay1, LOW);
}
      lcd.clear();

// LDR relay
 if(lighting value >700)
 {
   digitalWrite(relay2, HIGH);
 }
  if(lighting value <400)
 {
   digitalWrite(relay2, LOW);
 }
}



Here is my Arduino diagram;

Replace the AC components and relays with simple leds and resistors for testing. Does everything behave as desired? If so, problem is not the code.

1 Like

What is the current draw of that MH-Z19B sensor, and is that a regulated 9volt supply.
Put your finger on the 5volt regulator next to the DC socket, and feel if it's getting hot.
Current draw of the CO2 sensor and LCD backlight could overheat the 5volt regulator and reset the Mega. Add a serial print to setup() to test this theory.
Serial.println("Booting");

SoftwareSerial should not be used on a Mega.
You have three hardware serial ports available.
And what are the 1k resistors for.
Leo..

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.