LCD and rotary encoder stop working when changing code

Hello,

I’m working on a thermostat based on Evil Genius book. This is the code:

#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;//encoder pin A
int bPin = 7;//encoder pinB
int buttonPin = 6;//encoder push button
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

void setup()
{
  lcd.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  lcd.clear();
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  if (digitalRead(buttonPin))
  {
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  if (count == 1000)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
  }
  count ++;
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    return result;
}

float readTemp()
{
  long a = analogRead(analogPin);
  float temp = beta / (log(((1025.0 * resistance / a) - 33.0) / 33.0) +
  (beta / 298.0)) - 273.0;
  return temp;
}

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }float readTemp()
{
  
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.print(temp);
  return temp;
}
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}

void updateDisplay()
{
  lcd.setCursor(0,0);
  lcd.print("Actual: ");
  lcd.print(adjustUnits(measuredTemp));
  lcd.print(" o");
  lcd.print(mode);
  lcd.print(" ");
  lcd.setCursor(0,1);
  if (override)
  {
    lcd.print(" OVERRIDE ON   ");
  }
  else
  {
    lcd.print("Set:  ");
    lcd.print(adjustUnits(setTemp));
    lcd.print(" o");
    lcd.print(mode);
    lcd.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

This code works well with the hardware setup. Now, I want to use a DS18B20 temperature sensor instead a thermistor. As I’m not an evil genius, all I’ve done is to replace the function float readTemp() as follows:

float readTemp()
{

sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
//Serial.print(temp);
return temp;
}

Below is the whole program:

#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

#include <OneWire.h> //DS18B20
#include <DallasTemperature.h> //DS18B20
#define ONE_WIRE_BUS 9 //DS18B20 connected to..
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
  lcd.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  lcd.clear();
  sensors.begin();
  Serial.begin(9600);
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  if (digitalRead(buttonPin))
  {
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  if (count == 1000)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
  }
  count ++;
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    return result;
}

float readTemp()
{
  
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.print(temp);
  return temp;
}

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}

void updateDisplay()
{
  lcd.setCursor(0,0);
  lcd.print("Actual: ");
  lcd.print(adjustUnits(measuredTemp));
  lcd.print(" o");
  lcd.print(mode);
  lcd.print(" ");
  lcd.setCursor(0,1);
  if (override)
  {
    lcd.print(" OVERRIDE ON   ");
  }
  else
  {
    lcd.print("Set:  ");
    lcd.print(adjustUnits(setTemp));
    lcd.print(" o");
    lcd.print(mode);
    lcd.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

The program compiles and when is loaded the LCD does not show anything until the push switch in the rotary encoder is pressed (the original program displays both the actual temperature and set temperature straight away). Furthermore, when turning the knob the temperature setting does not change (again, this was working fine in the original program).
Why is this happening? All I’ve done is is to read the value from another pin. The temperature readings are correct, in fact, after pressing the encoder push button, the display shows the temperature but the set temperature cannot be adjusted with the knob.

I would appreciate any help as I really don’t know what is what I’m missing. I’m using Arduino Nano (ATmega328)

Thank you.

I recommend test below code. make ensure temrature sensor working fine

#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
 
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
}
 
 
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
 
}

make ensure you used A 4K7 ohm pullup resistor is required on the DQ pin to pull it up to 5V

gives the temperature value

sensors.requestTemperatures();

not the

Serial.print(sensors.getTempCByIndex(0));

You can call directly

sensors.requestTemperatures();

instead
measuredTemp

Thank you AMPS for your replay. Sadly it is not an issue with the thermometer, I have used DS1820 for a year with no issues in my datalogger. I have tried what you suggested, reading directly in the loop and nothing, furthermore I have tried with a DHT sensor and again the same issue.

Looks like for some reason stops working correctly when the pin to read is digital and not analog, but I think this does not make much sense....I'm baffled.....

Thanks

I have tried what you suggested, reading directly in the loop and nothing, furthermore I have tried with a DHT sensor and again the same issue.

can you able to read the temprature value here. Can you share serial output??

The code you posted not even compile. So check that first.

This part has fault .you decaring twice, You cant call function within function

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  float readTemp()
{
  
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.print(temp);
  return temp;
}
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}
float readTemp()
{
  long a = analogRead(analogPin);
  float temp = beta / (log(((1025.0 * resistance / a) - 33.0) / 33.0) +
  (beta / 298.0)) - 273.0;
  return temp;
}

So either one function has to be called.

#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;//encoder pin A
int bPin = 7;//encoder pinB
int buttonPin = 6;//encoder push button
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

void setup()
{
  lcd.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  lcd.clear();
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  //Serial.println("");
  Serial.print("measuredTemp:");
  Serial.println(measuredTemp);
  if (digitalRead(buttonPin))
  {
    Serial.println("update display:");
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  if (count == 1000)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
    Serial.print("couter reset:");
  }
  count ++;
  Serial.print("count:");
  Serial.println(count);
  Serial.println(".................................");
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    return result;
}

  float readTemp()
{
  
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
//  Serial.print(temp);
  return temp;
}
  


void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }

}

void updateDisplay()
{
  lcd.setCursor(0,0);
  lcd.print("Actual: ");
  lcd.print(adjustUnits(measuredTemp));
  lcd.print(" o");
  lcd.print(mode);
  lcd.print(" ");
  lcd.setCursor(0,1);
  if (override)
  {
    lcd.print(" OVERRIDE ON   ");
  }
  else
  {
    lcd.print("Set:  ");
    lcd.print(adjustUnits(setTemp));
    lcd.print(" o");
    lcd.print(mode);
    lcd.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

Check the code once,try what it does with encoder > please share me serial monitor

Sorry, just checking and while copying and pasting you’re right the code does not compile.

This is the code that is working and compiles with the thermistor:

#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

void setup()
{
  lcd.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  lcd.clear();
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  if (digitalRead(buttonPin))
  {
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  if (count == 1000)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
  }
  count ++;
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    return result;
}

float readTemp()
{
  long a = analogRead(analogPin);
  float temp = beta / (log(((1025.0 * resistance / a) - 33.0) / 33.0) +
  (beta / 298.0)) - 273.0;
  return temp;
}

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}

void updateDisplay()
{
  lcd.setCursor(0,0);
  lcd.print("Actual: ");
  lcd.print(adjustUnits(measuredTemp));
  lcd.print(" o");
  lcd.print(mode);
  lcd.print(" ");
  lcd.setCursor(0,1);
  if (override)
  {
    lcd.print(" OVERRIDE ON   ");
  }
  else
  {
    lcd.print("Set:  ");
    lcd.print(adjustUnits(setTemp));
    lcd.print(" o");
    lcd.print(mode);
    lcd.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

This is the code with the DS18B20 that makes the encoder stop working despite the sensor is working perfectly well:

#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

#include <OneWire.h> //DS18B20
#include <DallasTemperature.h> //DS18B20
#define ONE_WIRE_BUS 9 //DS18B20 connected to..
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);// Pass our oneWire reference 

void setup()
{
  lcd.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
  lcd.clear();
  Serial.begin(9600);
  sensors.begin();
  delay(1000);
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  if (digitalRead(buttonPin))
  {
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  if (count == 1000)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
  }
  count ++;
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    return result;
}

float readTemp()
{
  sensors.requestTemperatures();
  delay(50);
  float temp = sensors.getTempCByIndex(0);
  Serial.println(temp);
  return temp;
}

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}

void updateDisplay()
{
  lcd.setCursor(0,0);
  lcd.print("Actual: ");
  lcd.print(adjustUnits(measuredTemp));
  lcd.print(" o");
  lcd.print(mode);
  lcd.print(" ");
  lcd.setCursor(0,1);
  if (override)
  {
    lcd.print(" OVERRIDE ON   ");
  }
  else
  {
    lcd.print("Set:  ");
    lcd.print(adjustUnits(setTemp));
    lcd.print(" o");
    lcd.print(mode);
    lcd.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

Sorry about that my mistake while copying and pasting.

Have you tested my code.please include serial print statement Instead of LCD print.

Check How it behave . Print Serial Monitor Window here.

#include <LiquidCrystal.h>
#define beta 4090 // from your thermistor's datasheet
#define resistance 33
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4-7 on pins 5-2
//LiquidCrystal Serial(12, 11, 10, 5, 4, 3, 2);
int ledPin = 15;
int relayPin = 16;
int aPin = 8;
int bPin = 7;
int buttonPin = 6;
int analogPin = 0;

float setTemp = 20.0;
float measuredTemp;
char mode = 'C';
// can be changed to F

boolean override = false;
float hysteresis = 0.25;

#include <OneWire.h> //DS18B20
#include <DallasTemperature.h> //DS18B20
#define ONE_WIRE_BUS 9 //DS18B20 connected to..
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);// Pass our oneWire reference 

void setup()
{
 // Serial.begin(2, 20);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(aPin, INPUT);
  pinMode(bPin, INPUT);
  pinMode(buttonPin, INPUT);
 // Serial.clear();
  Serial.begin(9600);
  sensors.begin();
  delay(1000);
}

void loop()
{
  static int count = 0;
  measuredTemp = readTemp();
  Serial.print("measuredTemp:");
  Serial.println(measuredTemp);
  if (digitalRead(buttonPin))
  {
    Serial.print("update display");
    override = ! override;
    updateDisplay();
    delay(500); // debounce
   }else
   {
  int change = getEncoderTurn();
  setTemp = setTemp + change * 0.1;
  Serial.print("Set temprature:");
  Serial.println(setTemp);
   }
  if (count == 10)
  {
    updateDisplay();
    updateOutputs();
    count = 0;
    Serial.println("cponter set Zero:");
  }
  count ++;
  Serial.print("count:");
  Serial.println(count);
  Serial.println(".................");
  delay(1000);
  
}

int getEncoderTurn()
{
  // return -1, 0, or +1
  static int oldA = LOW;
  static int oldB = LOW;
  int result = 0;
  int newA = digitalRead(aPin);
  int newB = digitalRead(bPin);
  if (newA != oldA || newB != oldB)
   {
      // something has changed
      if (oldA == LOW && newA == HIGH)
      {
        result = -(oldB * 2 - 1);
      }
    }
    oldA = newA;
    oldB = newB;
    
    Serial.print("result:");Serial.println(result);
    return result;
}

float readTemp()
{
  sensors.requestTemperatures();
  delay(50);
  float temp = sensors.getTempCByIndex(0);
//  Serial.println(temp);
  return temp;
}

void updateOutputs()
{
  if (override || measuredTemp < setTemp - hysteresis)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  }
  else if (!override && measuredTemp > setTemp + hysteresis)
  {
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
}

void updateDisplay()
{
//  Serial.setCursor(0,0);
  Serial.print("Actual: ");
  Serial.print(adjustUnits(measuredTemp));
  Serial.print(" o");
  Serial.print(mode);
  Serial.print(" ");
//  Serial.setCursor(0,1);
  if (override)
  {
    Serial.print(" OVERRIDE ON   ");
  }
  else
  {
    Serial.print("Set:  ");
    Serial.print(adjustUnits(setTemp));
    Serial.print(" o");
    Serial.print(mode);
    Serial.print(" ");
  }
}

float adjustUnits(float temp)
{
  if (mode == 'C')
  {
    return temp;
  }
  else
  {
    return (temp * 9) / 5 + 32;
  }
}

This is the serial with your code when not pressing the encoder push button:

................. measuredTemp:19.87 result:0 Set temprature:20.10 count:8 .................

This is the serial when pressing the encoder push button:

measuredTemp:19.75 update displayActual: 19.75 oC OVERRIDE ON count:8 ................. measuredTemp:19.75 update displayActual: 19.75 oC Set: 20.20 oC count:9 ................. measuredTemp:19.75 update displayActual: 19.75 oC OVERRIDE ON count:10 ................. measuredTemp:19.75 update displayActual: 19.75 oC Set: 20.20 oC Actual: 19.75 oC Set: 20.20 oC cponter set Zero: count:1 .................

Thank you

The code is working fine as expected. Can you check the code again with LCD screen. Replace all serial by LCD. comment all Serial. print lines.

If you care fully check instruction; declare the change as global with static int.

measuredTemp:19.87 result:0 Set temprature:20.10 count:8

if you check carefully here. if result is zero

setTemp = setTemp + change * 0.1;

expected to be settemprature. SO add the serial print here.