It looks easy : temperature control for arduino . Can't get it to work!

Hi all,
i'm facing a rather simple problem that i can't get to work in my code :disappointed_relieved:

I have a heating/cooling controller that i want to setup with a dead zone. it has to work like this

Say it's 20 degrees in the room, the delta T is set to 1 degrees

and it is set to 20 -> do nothing
when it's set to 21, start heating -> when it reaches 21, stop heating (not on 22!)
when it's set to 19, start cooling -> when it reaches 19 , stop cooling (not on 18!)

anyone have any script or guidance ? thanx allot !!!!

Please post a sketch with your best effort at getting it to work

These 2 conditions sound mutually exclusive. Do you mean that when the temperature is less than 21 the heating should be on ?

Lets say the set temp is 20, and the delta T is set to 1

heating should start at 19° and cooling at 21 .

But heating or cooling have to stop at 20

Let me get my code, but it's pretty large.


    if ( (RoomTemp>(SetTemp-SetTDiff)) && (RoomTemp<(SetTemp+SetTDiff)) )
    {
       // all pumps and valves are closed, temperature is reached  
       Serial.println("--Temp OK");
       Heating = false;
       Cooling = false;
     }

    //Cooling 

    else  if (RoomTemp>(SetTemp-SetTDiff))
    {
       Cooling = true;
       Heating = false;
       // Set all the valves and pumps for cooling   (code removed)
   }


    // heating 
   else if (RoomTemp<(SetTemp+SetTDiff)) 
    {
       Heating = true;
       Cooling = false;
       // Set all the valves and pumps for heating    (code removed)
    }

Well you should post your complete sketch.
From the very first to the very last line of code

If your sketch has many many lines add some text where the interesting part is.

If you won't post your complete sketch I will just post

"some tips how to improve your posting-style"
instead of suggestions on how to code it.

best regards Stefan

1 Like

I had changed it in that way , that i added the condition of heatingo or cooling to the first IF

if ( ( (TVOCTemp<SetTemp) && Cooling==true) || ((TVOCTemp>SetTemp) && Heating==true ) )

but when i start the process, when the temperature is in reach, it does start the cooling and heating at the same time...

The code is 1500 lines long, i see no reason whatsoever to post it completely. It would'nt make
any sense.

tips how to improve your posting style

I get that. I will post it, but it just adds allot more confusion. try me.

Try us. Post it. As the official forum guidelines suggest.

Pseudocode:

if temp > high
  { cooling on }
if temp < mid
  { cooling off }
if temp < low
  { heat on }
if temp > mid
  { heat off }

As you can see, it's not rocket science.

#include <Controllino.h> 
#include "ModbusRtu.h"   
#include <OneWire.h>
#include <DallasTemperature.h>
#include <millisDelay.h>
#include <Ethernet.h>
#include <EthernetUdp.h>


#define UDP_TX_PACKET_MAX_SIZE  1024

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 200);

unsigned int localPort = 8001;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "";        // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP

EthernetUDP Udp; 

#define MasterModbusAdd  0
#define SlaveModbusAdd   1
#define FanModbusAdd     5
#define RS485Serial      3

// Declare variables : 
int Cel1Active,Cel1Running,Cel1Prior;
String result,tmp,ch;
char caracter;
uint16_t au16data[16];
uint16_t au16dataw[16];
uint8_t u8state,func;
int TVOCTemp,NewTVOCTemp, TVOCHum,SetTemp,SetHum,SetFan,SetTDiff,SetHDiff,SetHeatDelay,SetVatTemp,SetVatTempDiff,SetEvaporatorDiff,MaxVatT,MinVatT,PressDelay,slave,AlarmCount,LowTemp,HighTemp,LowHum,HighHum;;
String SetTempSTR,SetHumSTR,SetFanSTR,SetTempDiff,SetHumDiff,SetHeatDelaySTR,VatTempSTR,VatTempDiffSTR,EvaporatorDiffSTR,MaxVatTSTR,MinVatTSTR,PressDelaySTR,LowTempSTR,HighTempSTR,LowHumSTR,HighHumSTR;
int  temp1,temp2,temp3,temp4;
bool RO0,RO1,RO2,RO3,RO4,RO5,RO6,RO7,RO8,RO9,AlarmActive; // relay override statusses
bool TOk, ColdQ, HotQ,HeatDelayActive,DeHumidActive,HumidActive, Heating,Cooling,MagValve;
unsigned long HeatDelayTime, PressTime;
unsigned long u32wait;
unsigned long target_time = 0L ;
const unsigned long PERIOD = 10*1000UL;
int numReadings = 5;
int currentReading = 0;
int Deviation = 2; // 4 = 40% deviation readings are ignored
unsigned long AvgTemp1,AvgTemp2,AvgTemp3,AvgTemp4;
unsigned long AlarmDelayTime = 0; // in mS 
unsigned long AlarmInterval = 10000; // in mS 
int ActiveAlarmCode =0;
char ReceiveString[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char SendString[] ="";
String SendStr ;

millisDelay AlarmDelay;
 
Modbus master(MasterModbusAdd, RS485Serial, 0);
modbus_t data[16];

OneWire oneWire(2); // pin D6
DallasTemperature sensors(&oneWire);
DeviceAddress DST1 = {0x28, 0x1A, 0x6F, 0xA5, 0x13, 0x21, 0x01, 0x29};  // Warm water vat
DeviceAddress DST2 = {0x28, 0x7E, 0x65, 0x8E, 0x13, 0x21, 0x01, 0x6F};  // Koud water vat
DeviceAddress DST3 = {0x28, 0x99, 0x09, 0xD5, 0x13, 0x21, 0x01, 0xBF};  // Batterij IN 
DeviceAddress DST4 = {0x28, 0x07, 0xBF, 0x99, 0x13, 0x21, 0x01, 0x3C};  // Batterij UIT

//Backup sensor :  {0x28, 0xE0, 0x4E, 0xB9, 0x13, 0x21, 0x01, 0xB8};  
 
void setup() {
  Serial.begin(9600);
  // start the Ethernet
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start UDP
  Udp.begin(localPort);
  
  Serial.println("Connecting to Serial3 ");
  master.begin(19200,SERIAL_8E1);
  Serial.println("Connected");
  master.setTimeOut(5000); // if there is no answer in 5000 ms, roll over
  u32wait = millis() + 2000;
  u8state = 0; 
  slave=1;
  func=0;
  AlarmCount =0;
  HeatDelayActive = false;
  DeHumidActive = false;
  HumidActive = false;
  Heating = false;
  Cooling = false;
  MagValve = false;
  Cel1Active = 0;
  Cel1Running = false;
  pinMode(CONTROLLINO_A0, INPUT);
  pinMode(CONTROLLINO_A2, INPUT);
  pinMode(CONTROLLINO_R0, OUTPUT);
  pinMode(CONTROLLINO_R1, OUTPUT);
  pinMode(CONTROLLINO_R2, OUTPUT);
  pinMode(CONTROLLINO_R3, OUTPUT);
  pinMode(CONTROLLINO_R4, OUTPUT);
  pinMode(CONTROLLINO_R5, OUTPUT);
  pinMode(CONTROLLINO_R6, OUTPUT);
  pinMode(CONTROLLINO_R7, OUTPUT);
  pinMode(CONTROLLINO_R8, OUTPUT);
  pinMode(CONTROLLINO_R9, OUTPUT);

  RO0 = false;
  RO1 = false;
  RO2 = false;
  RO3 = false;
  RO4 = false;
  RO5 = false;
  RO6 = false;
  RO7 = false;
  RO8 = false;
  RO9 = false;  
  
  sensors.begin();
  sensors.setResolution(11);
  
  // MODBUS Registers
  // Temp
  data[0].u8id = SlaveModbusAdd; 
  data[0].u8fct = 4; 
  data[0].u16RegAdd =0; 
  data[0].u16CoilsNo = 1;
  data[0].au16reg = au16data; 
  // LV
  data[1].u8id = SlaveModbusAdd; 
  data[1].u8fct = 4; 
  data[1].u16RegAdd =9; 
  data[1].u16CoilsNo = 1; 
  data[1].au16reg = au16data; 
  // HVOC
  data[2].u8id = SlaveModbusAdd; 
  data[2].u8fct = 4; 
  data[2].u16RegAdd =25; 
  data[2].u16CoilsNo = 1; 
  data[2].au16reg = au16data; 
  //Sensor status
  data[3].u8id = SlaveModbusAdd; 
  data[3].u8fct = 4; 
  data[3].u16RegAdd =29; 
  data[3].u16CoilsNo = 1; 
  data[3].au16reg = au16data; 
 //Light sensor
  data[4].u8id = SlaveModbusAdd; 
  data[4].u8fct = 4; 
  data[4].u16RegAdd =40;
  data[4].u16CoilsNo = 1; 
  data[4].au16reg = au16data; 
   //Fan controller get value
  data[5].u8id = FanModbusAdd;
  data[5].u8fct = 3; 
  data[5].u16RegAdd =30; 
  data[5].u16CoilsNo = 1; 
  data[5].au16reg = au16data; 
   //Fan controller write value
  data[6].u8id = FanModbusAdd; 
  data[6].u8fct = 6; 
  data[6].u16RegAdd =30; 
  data[6].u16CoilsNo = 1; 
  data[6].au16reg = au16dataw; 
}

 
void loop() {

 SendStr="";
 SendStr = SendStr + digitalRead(CONTROLLINO_R0)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R1)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R2)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R3)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R4)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R5)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R6)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R7)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R8)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_R9)+"/";
 SendStr = SendStr + digitalRead(CONTROLLINO_A0)+"/";
 SendStr = SendStr + TVOCTemp  + "/";
 SendStr = SendStr + TVOCHum   + "/";
 SendStr = SendStr + abs(temp1)+ "/";
 SendStr = SendStr + abs(temp2)+ "/";
 SendStr = SendStr + abs(temp3)+ "/";
 SendStr = SendStr + abs(temp4)+ "/";
 SendStr = SendStr + Cel1Active+ "/";   
 SendStr = SendStr + Cel1Prior +"/" ;    
 SendStr = SendStr + ActiveAlarmCode ;    
 

 char SendString[SendStr.length()+1];
 SendStr.toCharArray(SendString, SendStr.length()+1);
  
 int packetSize = Udp.parsePacket();
 
  if (packetSize) {
    //Serial.print("Received packet of size ");
    //Serial.println(packetSize);
    //Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i=0; i < 4; i++) {
     // Serial.print(remote[i], DEC);
      if (i < 3) {
       // Serial.print(".");
      }
    }
 

    // read the packet into packetBufffer
    Udp.read(ReceiveString, UDP_TX_PACKET_MAX_SIZE);
 
    // send a reply to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(SendString);
    Udp.endPacket();
  }
  delay(100);
  
 ConvertReceivedData(ReceiveString);       

 ControlCel1();

}
// END LOOP


void ConvertReceivedData(String inputdata)
{
     
      if(inputdata.indexOf("E") > 0) // check if we have complete data 
      {
      inputdata.replace("ST","");
      inputdata.replace("E","");

      // Set Relays : 
      // Relay 0 , Magneetventiel
      if (getValue(inputdata, ':', 0).equals("1"))
      {
          digitalWrite(CONTROLLINO_R0, HIGH); 
          RO0 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R0, LOW); 
          RO0= false;
      }
      // Relay 1 : Compressor
       if (getValue(inputdata, ':', 1).equals("1"))
      {
          digitalWrite(CONTROLLINO_R1, HIGH); 
          RO1 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R1, LOW); 
          RO1 = false;
      }
      // Relay 2 :
      if (getValue(inputdata, ':', 2).equals("1"))
      {
          digitalWrite(CONTROLLINO_R2, HIGH); 
          RO2 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R2, LOW); 
          RO2 = false;
      }
      // Relay 3 :
      if (getValue(inputdata, ':', 3).equals("1"))
      {
          digitalWrite(CONTROLLINO_R3, HIGH); 
          RO3 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R3, LOW); 
          RO3 = false;
      }
      // Relay 4 :
      if (getValue(inputdata, ':', 4).equals("1"))
      {
          digitalWrite(CONTROLLINO_R4, HIGH); 
          RO4 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R4, LOW); 
          RO4 = false;
      }
      // Relay 5 :
      if (getValue(inputdata, ':',5).equals("1"))
      {
          digitalWrite(CONTROLLINO_R5, HIGH); 
          RO5 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R5, LOW); 
          RO5 = false;
      }
      // Relay 6 :
      if (getValue(inputdata, ':',6 ).equals("1"))
      {
          digitalWrite(CONTROLLINO_R6, HIGH); 
          RO6 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R6, LOW); 
          RO6 = false;
      }
      // Relay 7 :
      if (getValue(inputdata, ':', 7).equals("1"))
      {
          digitalWrite(CONTROLLINO_R7, HIGH); 
          RO7 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R7, LOW); 
          RO7 = false;
      }
      // Relay 8 :
      if (getValue(inputdata, ':', 8).equals("1"))
      {
          digitalWrite(CONTROLLINO_R8, HIGH); 
          RO8 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R8, LOW); 
          RO8 = false;
      }
      // Relay 9 , ALARM :
      if (getValue(inputdata, ':', 9).equals("1"))
      {
          digitalWrite(CONTROLLINO_R9, HIGH); 
          RO9 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R9, LOW); 
          RO9 = false;
      }

      // Set Vars
      
      if (getIntValue(inputdata, ':', 10)!=0){
         SetTemp        = getIntValue(inputdata, ':', 10);
      }
      if (getIntValue(inputdata, ':', 11)!=0){
         SetHum        = getIntValue(inputdata, ':', 11);
      }
      if (getIntValue(inputdata, ':', 12)!=0){
         SetFan        = getIntValue(inputdata, ':', 12);
      }
      if (getIntValue(inputdata, ':', 13)!=0){
         SetTDiff        = getIntValue(inputdata, ':', 13);
      }
      if (getIntValue(inputdata, ':', 14)!=0){
         SetHDiff        = getIntValue(inputdata, ':', 14);
      }
      if (getIntValue(inputdata, ':', 15)!=0){
         SetHeatDelay    = getIntValue(inputdata, ':', 15);
      }
      if (getIntValue(inputdata, ':', 16)!=0){
         SetVatTemp        = getIntValue(inputdata, ':', 16);
      }
        if (getIntValue(inputdata, ':', 17)!=0){
         SetVatTempDiff        = getIntValue(inputdata, ':', 17);
      }
        if (getIntValue(inputdata, ':', 18)!=0){
         SetEvaporatorDiff        = getIntValue(inputdata, ':', 18);
      }
        if (getIntValue(inputdata, ':', 19)!=0){
         MaxVatT        = getIntValue(inputdata, ':', 19);
      }
        if (getIntValue(inputdata, ':', 20)!=0){
         MinVatT        = getIntValue(inputdata, ':', 20);
      }
        if (getIntValue(inputdata, ':', 21)!=0){
         PressDelay        = getIntValue(inputdata, ':', 21);
      }
        if (getIntValue(inputdata, ':', 22)!=0){
         LowTemp        = getIntValue(inputdata, ':', 22);
      }
        if (getIntValue(inputdata, ':', 23)!=0){
         HighTemp        = getIntValue(inputdata, ':', 23);
      }
        if (getIntValue(inputdata, ':', 24)!=0){
         LowHum        = getIntValue(inputdata, ':', 24);
      }
        if (getIntValue(inputdata, ':', 25)>0){
         HighHum        = getIntValue(inputdata, ':', 25);
      }
      if (getIntValue(inputdata, ':', 26)==0){
         Cel1Active = 0;
      }   
      else{
        Cel1Active = 1;
      }
      if (getIntValue(inputdata, ':', 27)>0){
         Cel1Prior = 1;  // PRIOR HUM
      }   
      else{
         Cel1Prior = 0;  // PRIOR TEMP
      }

      // Relay 9 : ALARM
      if (getValue(inputdata, ':',27 ).equals("1"))
      {
          digitalWrite(CONTROLLINO_R9, HIGH); 
          RO6 = true;
      }
      else
      {
          digitalWrite(CONTROLLINO_R9, LOW); 
          RO6 = false;
      }
   }
}


void ControlCel1()
{

  //Check Temp Every 10s
  if (millis () - target_time >= PERIOD)
  {
    target_time += PERIOD ;   // change scheduled time exactly, no slippage will happen
    sensors.setWaitForConversion(false);  // makes it async
    delay(100);
    sensors.requestTemperatures();
    sensors.setWaitForConversion(false);
    temp1 =  sensors.getTempC(DST1)*10;
    temp2 =  sensors.getTempC(DST2)*10;
    temp3 =  sensors.getTempC(DST3)*10;
    temp4 =  sensors.getTempC(DST4)*10;
    sensors.setWaitForConversion(true);

    //temporary changes : 
    TVOCTemp = temp3;
    TVOCHum = analogRead(CONTROLLINO_A2)+130;
    if (TVOCHum>1000)
    {
      TVOCHum = 1000;
    } 
 

}
   
   // Disable all relays
   if (Cel1Active==0 && Cel1Running==true)
   {
       if (RO0 == false) {
          digitalWrite(CONTROLLINO_R0, LOW); 
       }
       if (RO1 == false) {
          digitalWrite(CONTROLLINO_R1, LOW); 
       }
       if (RO2 == false) {
          digitalWrite(CONTROLLINO_R2, LOW); 
       }
       // Pomp warm water uit
       if (RO3 == false) {
          digitalWrite(CONTROLLINO_R3, LOW); 
       }
        // Ventiel koud water dicht
       if (RO4 == false) {
          digitalWrite(CONTROLLINO_R4, LOW); 
       }
       // Ventiel warm water dicht
       if (RO5 == false) {
          digitalWrite(CONTROLLINO_R5, LOW); 
       }
       // Weerstand vat uit
       if (RO6 == false) {
          digitalWrite(CONTROLLINO_R6, LOW); 
       }
        // Stoombevochtiger uit
       if (RO7 == false) {
          digitalWrite(CONTROLLINO_R7, LOW); 
       }
       if (RO8 == false) {
          digitalWrite(CONTROLLINO_R8, LOW); 
       }
       if (RO9 == false) {
          digitalWrite(CONTROLLINO_R9, LOW); 
       }
       delay (250);
       Cel1Running = false;
  }       
    
      
      
  if (TVOCTemp>0 && SetTemp>0 && TVOCHum>0 && SetHum>0 && Cel1Active>0) // Make sure we have a reading
  {
     Cel1Running=true;
     
    if  ((TVOCHum<SetHum && DeHumidActive == true) || (TVOCHum>SetHum && HumidActive == true))
   
    {
      
       Serial.println("--Vocht OK");
       DeHumidActive = false ;
       HumidActive = false;
       HeatDelayActive = false;
       //pomp koud water uit , enkel indien compressor niet draait.
       if (RO2 == false && digitalRead(CONTROLLINO_R1) == LOW ) {
          digitalWrite(CONTROLLINO_R2, LOW); 
       }
       // Pomp warm water uit
       if (RO3 == false && digitalRead(CONTROLLINO_R1) == LOW ) {
          digitalWrite(CONTROLLINO_R3, LOW); 
       }
        // Ventiel koud water dicht
       if (RO4 == false) {
          digitalWrite(CONTROLLINO_R4, LOW); 
       }
       // Ventiel warm water dicht
       if (RO5 == false) {
          digitalWrite(CONTROLLINO_R5, LOW); 
       }
       // Weerstand vat uit
       if (RO6 == false) {
          digitalWrite(CONTROLLINO_R6, LOW); 
       }
        // Stoombevochtiger uit
       if (RO7 == false) {
          digitalWrite(CONTROLLINO_R7, LOW); 
       }
    }


    // Ontvochtingen
 
    if (((TVOCHum - SetHDiff)>SetHum)  && ( Cel1Prior == 1 || (Cel1Prior == 0 && Heating ==false && Cooling== false)))
    {
    Serial.println("--Ontvochtigen");
      DeHumidActive = true;
      
      digitalWrite(CONTROLLINO_R2, HIGH); 
      digitalWrite(CONTROLLINO_R3, HIGH); 
      digitalWrite(CONTROLLINO_R4, HIGH); 
      digitalWrite(CONTROLLINO_R5, HIGH); 
          
       if (HeatDelayActive == false)
       {
          HeatDelayTime = millis();
          HeatDelayActive = true;
       }
      
       if (((millis() - HeatDelayTime) >= (SetHeatDelay*60000)) && HeatDelayActive == true)
       {
           // Activeer weerstand warm water vat
           digitalWrite(CONTROLLINO_R6, HIGH);  
       }

       if (RO7 == false) {
          digitalWrite(CONTROLLINO_R7, LOW); 
       }
     
    }

    // Bevochtigen
 
    if (((TVOCHum + SetHDiff)>SetHum) && ( Cel1Prior == 1 || (Cel1Prior == 0 && Heating ==false && Cooling== false)))
    {
    Serial.println("--Bevochtigen");
      HumidActive = true;
      digitalWrite(CONTROLLINO_R7, HIGH); 
     
    }
    
   
    if ( (TVOCTemp>(SetTemp-SetTDiff)) && (TVOCTemp<(SetTemp+SetTDiff)) )
    {
      Serial.println("--Temp OK");
       // Temperatuur is binnen bereik : 
       HeatDelayActive = false;
       
       Heating = false;
       Cooling = false;
       //Serial.println("--Temp OK");
      //pomp koud water uit , enkel indien compressor niet draait.
       if (RO2 == false && digitalRead(CONTROLLINO_R1) == LOW ) {
          digitalWrite(CONTROLLINO_R2, LOW); 
       }
       // Pomp warm water uit
       if (RO3 == false && digitalRead(CONTROLLINO_R1) == LOW ) {
          digitalWrite(CONTROLLINO_R3, LOW); 
       }
        // Ventiel koud water dicht
       if (RO4 == false) {
          digitalWrite(CONTROLLINO_R4, LOW); 
       }
       // Ventiel warm water dicht
       if (RO5 == false) {
          digitalWrite(CONTROLLINO_R5, LOW); 
       }
       // Weerstand vat uit
       if (RO6 == false) {
          digitalWrite(CONTROLLINO_R6, LOW); 
       }
     }

    //Koudeaanvraag
       
    else  if ((TVOCTemp>(SetTemp-SetTDiff)) && ( Cel1Prior == 0 || (Cel1Prior == 1 && HumidActive == false && DeHumidActive == false)))
    {
       Serial.println("--Koude aanvraag");
       Cooling = true;
       Heating = false;
       HeatDelayActive = false;
       // Pomp koud water aan
       digitalWrite(CONTROLLINO_R2, HIGH); 
       // Pomp warm water uit
       if (RO3 == false && digitalRead(CONTROLLINO_R1) == LOW  && DeHumidActive == false ) {
          digitalWrite(CONTROLLINO_R3, LOW); 
       }
       // Koud water ventiel open
       digitalWrite(CONTROLLINO_R4, HIGH); 
        // Ventiel warm water dicht
       if (RO5 == false  && DeHumidActive == false) {
          digitalWrite(CONTROLLINO_R5, LOW); 
       }
   }

   //Warmte aanvraag
   else if ((TVOCTemp<(SetTemp+SetTDiff))  && ( Cel1Prior == 0 || (Cel1Prior == 1 && HumidActive == false && HumidActive == false)))
    {
    
       Serial.println("--Warmte aanvraag");
       Serial.print("--TVOC Temp");
       Serial.println(TVOCTemp);
       Serial.print("--SetTemp");
       Serial.println(SetTemp);
        Serial.print("--SetTempDiff");
       Serial.println(SetTDiff);
       Heating = true;
       Cooling = false;
       
       if (HeatDelayActive == false)
       {
          HeatDelayTime = millis();
          HeatDelayActive = true;
       }
      
       if (((millis() - HeatDelayTime) >= (SetHeatDelay*60000)) && HeatDelayActive == true)
       {
           // Activeer weerstand warm water vat
      //     digitalWrite(CONTROLLINO_R6, HIGH);    // tijdelijk uit
       }
      
       // Pomp warm water aan
       digitalWrite(CONTROLLINO_R3, HIGH); 
       
       if (RO2 == false && digitalRead(CONTROLLINO_R1) == LOW ) {
          digitalWrite(CONTROLLINO_R2, LOW); 
       }

  
       
       // Warm water ventiel open
       digitalWrite(CONTROLLINO_R5, HIGH); 
       
       // Ventiel koud water dicht, enkel indien geen override vanuit de pc
       if (RO4 == false) {
          digitalWrite(CONTROLLINO_R4, LOW); 
       }
    }
   
    //Compressor sturing
    // Als temperatuur in vat te hoog komt.
    if (((temp2) - SetVatTempDiff)>SetVatTemp)
    {
      Serial.print("Magneetventiel:");
      Serial.println(digitalRead(CONTROLLINO_R0));
      Serial.print("Pressostaat:");
      Serial.println(digitalRead(CONTROLLINO_A0));
      
       //Serial.println("--Compressor Sturing");
       // Magneetventiel AAN
       if (digitalRead(CONTROLLINO_R0)== LOW && MagValve == false)
       {
        MagValve = true;
        PressTime = millis();
          Serial.print("Magneetventiel AAN:");
       // digitalWrite(CONTROLLINO_R0, HIGH); 
       }
   
      // Als Pressostaat HOOG is , start compressor :
       if (digitalRead(CONTROLLINO_A0)==HIGH)
       {
          Serial.print("Compressort AAN:");
        //  digitalWrite(CONTROLLINO_R1, HIGH); 
        //  digitalWrite(CONTROLLINO_R2, HIGH); 
        //  digitalWrite(CONTROLLINO_R3, HIGH); 
       }

      // Als Pressostaat LAAG is , stop compressor :
       if (digitalRead(CONTROLLINO_A0)==LOW)
       {
        Serial.print("Compressort UIT:");
       //   digitalWrite(CONTROLLINO_R1, LOW); 
        //  digitalWrite(CONTROLLINO_R2, LOW); 
        //  digitalWrite(CONTROLLINO_R3, LOW); 
       }

     if  ( (millis() - PressTime) >= (PressDelay*1000))
     {
      if (digitalRead(CONTROLLINO_R0) == HIGH && digitalRead(CONTROLLINO_A0) == LOW )
      {
      
           // Alarm motor start niet 
        //   SendAlarm(10);
        //   AlarmCount++;
           
       }
     }
    delay (200);
       
    }

  
   // if ((abs(temp2*10) + SetVatTempDiff) < SetVatTemp)
    if (abs(temp2)<=SetVatTemp)    
    {
       //magneetvenitel uit     
       digitalWrite(CONTROLLINO_R0, LOW); 
       Serial.print("Magneetventiel UIT:");
       // Als Pressostaat LAAG is , compressor uit :
       if (digitalRead(CONTROLLINO_A0)==0) 
       {
          if (RO0 == false) {
             // Compressor UIT
             digitalWrite(CONTROLLINO_R1, LOW); 
                  Serial.print("Compressor UIT: (door temp bereikt)");
             MagValve = false;
          }
       }
    }

    AlarmCount = 0;
    // Set Alarms :
    if ((LowTemp>0) && (LowTemp>TVOCTemp))  // Temp te laag
    {
       SendAlarm(20);
       AlarmCount++;
    }
    if (HighTemp>0 && HighTemp<TVOCTemp) // Temp te hoog
    {
       SendAlarm(21);
        AlarmCount++;
    }
    if (LowHum>0 && LowHum>TVOCHum) // Hum te laag
    {
       SendAlarm(22);
        AlarmCount++;
    }
    if (HighHum>0 && HighHum<TVOCHum/10) // Hum te hoog
    {
       SendAlarm(23);
       AlarmCount++;
    }

    // Als koud water vat te koud is 
    if (abs(temp2)< MinVatT)
    {
       SendAlarm(24);
         AlarmCount++;
    }

    // Als warm water vat te warm is 
    if (abs(temp2)> MaxVatT)
    {
       SendAlarm(25);
         AlarmCount++;
    }


    if ( AlarmCount == 0 )
    {
        AlarmDelay.stop(); 
        ActiveAlarmCode = 0;
    }
  } // End IF TVOC>0

          
 

}

void SendAlarm(int AlarmCode)
{
    if (AlarmDelay.justFinished()) {
        /*Serial.println("Just Finshed");
        delay(100);*/
        AlarmActive = true;
        ActiveAlarmCode = AlarmCode;
        AlarmDelay.repeat();
     }
     if (AlarmDelay.isRunning()==false && AlarmActive == false) {
     /*   Serial.println("AlarmDelay Started");
        delay(100);*/
        AlarmDelayTime = AlarmInterval;  // Wait x minutes between alarms.
        AlarmDelay.start(AlarmDelayTime); 
        ActiveAlarmCode = AlarmCode;
     }

      if (AlarmDelay.isRunning()==true && AlarmActive == true) {
   
     //  
     }

     
  }


String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

int getIntValue(String data, char separator, int index)
{  
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;
    String result;
    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    result = found > index ? data.substring(strIndex[0], strIndex[1]) : "";
    return result.toInt();
}



void ResetAlarm()
{
     if (RO9 == false) {
          digitalWrite(CONTROLLINO_R9, LOW); 
     }
     AlarmActive = false;
  
     AlarmDelayTime = 0; // Set it to 0 to make the next alarm trigger immediatly
}

/* ALARMLIJST------------------------------------------------*/
/* 10 Compressor start niet                                  */
/* 20 Temp te laag                                           */
/* 21 Temp te hoog                                           */
/* 22 Hum te laag                                            */
/* 23 Hum te hoog                                            */
/* 24 Koud Vat Temp te laag                                  */
/* 25 Warm Vat Temp te hoog                                  */
/* ----------------------------------------------------------*/

not sure what this will add to a solution of my problem here...

Probably because you haven't read the detailed explanation of that in the introductory threads that were recommended to you.

For cooling...

should be

(RoomTemp>=(SetTemp+SetTDiff))

For heating...

should be...

(RoomTemp<=(SetTemp-SetTDiff))

Thats not nearly even close to what i'm asking. Did you read the question ?

no , not true. Tested.

/*
  Lets say the set temp is 20, and the delta T is set to 1
  heating should start at 19° and cooling at 21 .
  But heating or cooling have to stop at 20
*/

int hot = 0;
int target = 20;
int cold = 0;
int deltaT = 1;
//----------------------------------------
void setup() {
}
//----------------------------------------
void loop() {
  if (hot < target)
  {
    // Increase hot + deltaT
  }
    if (cold  > target)
  {
    // decrease cold - deltaT
  }
}

your code is wrong... have a closer look. For cooling... you have
(RoomTemp>(SetTemp-SetTDiff))

If RoomTemp is 20, SetTemp is 20, Set Diff is 1, 20>20-1 is true... duh.

AND... your attitude sucks...

Yes, and you are wrong. My code does exactly as you ask. Except, you posed it with varying setpoint values and I used symbolic (high, mid, low) values. My code would behave exactly as you described.

When you change 20 to 21, you are setting 'mid' to 20. Your 'high' is 21. If you set 'mid' to 21, 'high' would be 22, and 'low' would be 20. Because you are deriving the high and low hysteresis points relative to the mid, in your code.

e.g.

high = mid +1
low = mid - 1
if temp > high
  { cooling on }
if temp < mid
  { cooling off }
if temp < low
  { heat on }
if temp > mid
  { heat off }

I'll write a sample prog with this, and come back with the results. thanks