Arduino nano, max6675 and triac soldering station

I decided to built the the project from the link below, and I need to know if the function that blocks the program is correct (it was wrote by me) and I also need to know if the function is correctly called in that line of code - in the setup part of the program, right after reading the temperature.

void errorFunction () {
realTemperature = thermocouple.readCelsius();
if (isnan(realTemperature) or realTemperature >= 432){
   while(true){
   digitalWrite(triac, low);
   digitalWrite(relay,low); // the relay will disconnect the power to the soldering iron heating element
    // here I will add the code to display the error
    // for example: "ERROR !!!"
   }
}
}

The project:

"triac" is the pin of the triac
"relay " is the pin that controls a relay that cuts off the power to the heating element when a error is detected.

I need some advice, or some code that could help me in solving this problem.

I had expected that the errorFunction() returns a value indicating whether everything is fine. Then your main program can handle normal and error states differently.

Where do you want to display the error message?

The error messages will be displayed on a 5110 LCD for tests. The final version will use a 1602 LCD.

I have re-wrote the function:

byte errorFunction () {
  realTemperature = thermocouple.readCelsius();
  if (isnan(realTemperature) or realTemperature >= 432) {
    while (true) {
      digitalWrite(triac, LOW);
      digitalWrite(relay, LOW); // the relay will disconnect the power to the soldering iron heating element
      lcd.setCursor(0, 0);
      lcd.print("ERROR !!!");
      delay(200);
    }
  } else {
    return 1;
  }
}

Should I add in the main program a condition that updates the display and call the attachinterrupt function when there is no overheating and no wires are disconnected from the thermocouple ?

Here is the code that I modified in order to display a error message on the lcd when the temp goes above 432 C or when the TC gets disconnected:

#include <PCD8544.h>
#include <SPI.h>
#include <Wire.h>
#include <max6675.h>

#define thermoDO 11
#define thermoCS 12
#define thermoCLK 13
#define potentiometer A0
#define zerocrossing 2
#define triac 7
#define relay 9

float temperature, realTemperature;
int pottemperature;
int counter;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

PCD8544 lcd;

void setup() {
  lcd.begin(84, 48);
  pinMode(potentiometer, INPUT);
  pinMode(zerocrossing, INPUT_PULLUP);
  pinMode(triac, OUTPUT);
  digitalWrite(triac, LOW);
  counter = 0;
  realTemperature = thermocouple.readCelsius();
  temperature = 0.779828 * realTemperature - 10.3427;
  updatedisplay();
  attachInterrupt(0, zero, RISING);
}

void loop() {
}

void zero() {
  counter++;
  if (counter < 40) {
    if (temperature <= pottemperature) {
      digitalWrite(triac, HIGH);
    }
    else {
      digitalWrite(triac, LOW);
    }
  }

  if (counter == 40) {
    digitalWrite(triac, LOW);
    detachInterrupt(0);
    realTemperature = thermocouple.readCelsius();
    temperature = 0.779828 * realTemperature - 10.3427;
    updatedisplay();
    counter = 0;
    attachInterrupt(0, zero, RISING);
  }
}

void updatedisplay() {
  pottemperature = analogRead(potentiometer);
  pottemperature = map(pottemperature, 0, 1023, 0, 400);
  checkForErrors();
  lcd.setCursor(0, 0);
  lcd.print("SET= ");
  lcd.print(5, 0);
  lcd.print(pottemperature);
  lcd.setCursor(0, 1);
  lcd.print("READ= ");
  lcd.setCursor(7, 1);
  lcd.print((int)temperature);
  delay(200);

}

void checkForErrors() {
  realTemperature = thermocouple.readCelsius();
  if (isnan(realTemperature) or realTemperature >= 432) {
    while (true) {
      detachInterrupt(0);
      digitalWrite(triac, LOW);
      digitalWrite(relay, LOW); // the relay will disconnect the power to the soldering iron heating element
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Error !");
      delay(500);
    }
  }
}

Hello, I would like to built the project from this web site:

Please let me know if the circuit will work the same if I will use standard connection ( https://www.arduino.cc/en/Tutorial/HelloWorld ) for the 1602 LCD display instead of i2c ?

At least you'll have to call the lcd.begin() version for the parallel interface.