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;