Arduino uno lcd 16x2 i2c and serial print stuck can't update read data sensor

Hello, can some one help me to troubleshooting my project?

My project uses PID method to keep temperature stable and set interval to display its sensor reading, problem is serial print and lcd won't update reading data from sensor after a while, when my project restarts, update reading comes back and crashes after a while. What should i do? thanks

this is the code i made:

#include <max6675.h>
#include <SPI.h>
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
LiquidCrystal_PCF8574 lcd(0x3f);
#include "HX711.h"

// LOAD CELL
HX711 scale;
float calibration_factor = 23.5;
int units;
float ounces;
#define DOUT  A1
#define CLK  A0

// THERMOCOUPLE
int thermo_so_pin  = 10;
int thermo_cs_pin  = 12;
int thermo_sck_pin = 13;
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);

//PID
float SV, PV;
int MV, start;
float PVf, PVf_1, fc, RC, a;
float  ut, ut_1;
float et, et_1, eint, eint_1, eint_update, edif;
float Kp, Ti, Td, Ki, Kd, PID, P, I, D;
unsigned long t;
double t_1, Ts;
float interval_elapsed, interval_limit;

//LCD
byte pic_termo[8] =          //icon termometer
{
  B00100,
  B01010,
  B01010,
  B01110,
  B01110,
  B11111,
  B11111,
  B01110,
};
byte pic_massa[] = {        //icon neraca
  B11111,
  B01010,
  B01010,
  B10001,
  B10111,
  B11111,
  B11111,
  B11111
};

//DRIVER PEMANAS
int AC_LOAD = 5;
int dimming = 128;

//PUSH BUTTON
const int start_btn = 4;
const int berat_btn = 3;
int berat_cabe;
bool lock_berat = true;
float berat_save = 0;
float berat30p = 0;

void setup() {
  Serial.begin(9600);

  //LOAD CELL
  scale.begin(DOUT, CLK);
  scale.set_scale();
  scale.tare();
  long zero_factor = scale.read_average();

  //FILTER DIGITAL
  fc = 3.6;
  RC = 1 / (6.28 * fc);
  Ts = 0.001;
  a = RC / Ts;
  PVf_1 = 0;

  //PARAMATER KENDALI
  Kp = 16.68;
  Ti = 1386;
  Td = 47.8;
  Ki = Kp / Ti;
  Kd = Kp * Td;

  //LCD DISPLAY
  Wire.setClock(10000);
  interval_elapsed = 0;
  interval_limit = 5;
  lcd.begin(16, 2);
  lcd.setBacklight(255);
  lcd.createChar(1, pic_termo);
  lcd.createChar(2, pic_massa);
  lcd.setCursor(0, 0);
  lcd.write(1);
  lcd.print(" ");
  lcd.setCursor(8, 0);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.write(2);
  lcd.print(" ");
  t = 0;

  //INISIALISASI PIN
  pinMode(start_btn, INPUT_PULLUP); //START BUTTON
  pinMode(berat_btn, INPUT_PULLUP); //PILIH BERAT BUTTON
  pinMode(A2, OUTPUT); //BUZZER
  pinMode(7, OUTPUT); //RELAY AC
  pinMode (6, OUTPUT); //RELAY DC
  pinMode(AC_LOAD, OUTPUT); //OUTPUT KENDALI
  attachInterrupt(0, zero_crosss_int, RISING); //ZERO CROSSING DRIVER PEMANAS
  pinMode(start_btn, HIGH);
}

//Z-C DRIVER PEMANAS
void zero_crosss_int() {
  int dimtime = (75 * dimming);
  delayMicroseconds(dimtime);
  digitalWrite(AC_LOAD, HIGH);
  delayMicroseconds(10);
  digitalWrite(AC_LOAD, LOW);
}

void loop() {
  beratcabe();

  load_cell();

  //START BUTTON
  start = digitalRead(start_btn);
  if (start == 1) {
    SV = 70;
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
    lock_berat = true;
    if (units <= berat30p) {
      analogWrite(A2, 1023);
    }
  }
  else if (start == 0) {
    SV = 0;
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);
    analogWrite(A2, 0);
  }

  suhu();

  t_1 = t;
  t = millis();
  Ts = (t - t_1) / 1000;

  // PERHIUTNGAN PID
  et = SV - PVf;
  eint_update = ((et + et_1) * Ts) / 2;
  eint = eint_1 + eint_update;
  edif = (et - et_1) / Ts;

  PID = Kp * et + Ki * eint + Kd * edif;
  PID = PID / 1;

  if (PID > 255) {
    PID = 255;
  }
  else if (PID < 0) {
    PID = 0;
  }

  //OUTPUT KENDALI KE DRIVER PEMANAS
  dimming = map(PID, 0, 255, 80, 0);

  // MENAMPILKAN DATA KE LCD
  interval_elapsed = interval_elapsed + Ts;
  if (interval_elapsed >= interval_limit) {
    interval_elapsed = 0;
    lcd.setCursor(2, 0);
    lcd.print(PVf);
    lcd.print(" ");
    lcd.setCursor(2, 1);
    lcd.print(units);
    Serial.print(70);
    Serial.print(" / ");
    Serial.println(PVf);
  }
  else {
    interval_elapsed = interval_elapsed;
  }
}

void beratcabe() {
  //PILIH INPUT BERAT CABAI
  berat_cabe = digitalRead(berat_btn);
  if (berat_cabe == 1) {
    lcd.setCursor(5, 1);
    lcd.print(" / 500 g");
  } else if (berat_cabe == 0) {
    lcd.setCursor(6, 1);
    lcd.print(" / 1000 g");
  }
}

void load_cell() {
  //PEMBACAAN BERAT CABAI
  scale.set_scale(calibration_factor);
  units = scale.get_units(), 10;
  if (units < 0)
  {
    units = 0.00;
  }
  if (lock_berat == true) {
    berat_save = units;
    berat30p = berat_save * 0.3;
    lock_berat = false;
  }
}

void suhu() {
  //FILTER DIGITAL THERMOCOUPLE
  PV = thermocouple.readCelsius();
  PVf = (PV + a * PVf_1) / (a + 1);
  PVf_1 = PVf;
}

this is the wiring for my project.

Read the forum guidelines. Post your test code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code. Un-indented code is harder to read and follow.

Do your serial or lcd prints give a clue as to where the code stops?

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

idk, but i think the serial or lcd stop update because of the millis function to set the data display time maybe

Insert, temporary, serial prints to try to localize the problem. Print variable values and indicators of program progress.

Is this what you mean? Monitor the value of interval_elapsed. Can interval_elapsed overflow?

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