Heater is not turning off

I use this code to controll a heater with arduino uno, and when the temprature reaches the one i set the heater doesent turn off, is there anything wrong with the code ?

#include "max6675.h"

int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 10;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
#define SSD_PIN 2

#define ANALOG_VOTLAGE_REFERENCE 5

float currentTemperature;
float highTargetTemperature = 40;
float lowTargetTemperature = 40;

void setup() {
Serial.begin(9600);
pinMode(SSD_PIN, OUTPUT);
}

void loop() {
currentTemperature = getTemperature();
Serial.print("Deg C = ");
Serial.print(ktc.readCelsius());

if (currentTemperature < lowTargetTemperature) {
digitalWrite(SSD_PIN, HIGH);
}

if (currentTemperature > highTargetTemperature) {
digitalWrite(SSD_PIN, LOW);
}
delay(500);
}
float getTemperature() {
ktc;
}

float getTemperature()
{
  ktc;
}

What is this supposed to do ?

float highTargetTemperature = 40;
float lowTargetTemperature = 40;

Shouldn't these be different from each other ?

I don't really know what i should put there, i need to "declare" getTemprature, the temps are supposed to be different, it was just me experimenting

Take another look at the library examples. For your setup
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
The only two functions you will use are

ktc.readCelcius()
ktc.readFarenheit()

They both return floats.

So i should remove currentTemperature and replace it with ktc.readCelcius() ?

So I should remove currentTemperature and replace it with ktc.readCelcius() ?

Not exactly. It's best to only read temperature once each pass of loop().

At the top of loop use

 currentTemperature = ktc.readCelsius();

Then, everywhere your print or act on temperature values, use currentTemperature.

Thanks for the help, I'll test it and hopefully you won't hear from me again :slight_smile: