So i got this problem driving relays on a given time temperature controlled

Hello,
I'm currently working on a project to control an old freezer.
to automate this process i am using:
Arduino NANO

  1. 1x waterproof DS18B20 temperature sensor
  2. I2C DS3231 real time clock module:
  3. I2C LCD 20X4
  4. 3x LED with a 270 ohm current limiting resistor to signal
  5. 2x pushbuttons to turn up or down the temperature
  6. a 4 channel 5V relay module (which will be replaced with a 5V OMRON G3MB-202P when i
    make it to a pcb )//same thing as the 5V Songle relays
    (the small relays will drive 230V high power relays)
  7. external 5V power supply for the 5V relays (connected for complete opto isolation)(no common grounds)

so the code i wrote to use is this one:

#include <DS3231.h>////real time clock libary
#include <OneWire.h>//sensor communication libary
#include <LiquidCrystal_I2C.h>//i2c_lcd libary
#include <DallasTemperature.h>//DS18B20 temperature sensor libary


//----------------Libaries-setup-------------------------------------------------------------------------------
//----------------I2C-Real-Time-Clock-D3231-setup--------------------------------------------------------------
DS3231  rtc(SDA, SCL);
Time t;
// ---------------DS18B20-temperature-sensor-setup-------------------------------------------------------------
int SensorDataPin = 2;//datapin for the sensor this cannot be changed because of the DellasTemperature libary
OneWire oneWire(SensorDataPin);//onewire setup 
DallasTemperature sensors(&oneWire); //onewire setup 
float tempCelsius;// the value of the measured temperature in celcius
//arduino D2 is the sensor pin
//DellasTemperature.h is the libary needed for the DS18B20
int setTemp = -10; //default temperature = -10 degrees celcius this is adjustable to any temperature. 
// Note that how higher the temperature is the more the relais have to switch 
// temperature cannot be set lower than -30 this is because of the cooling plant limitations
// on the lcd screen it is possible to do but not relaiable
//----------------I2C-LCD-20X4-setup--------------------------------------------------------------------------
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x03F, 20, 4);
//arduino nano analog pin 4 = SDA
//arduino nano analog pin 5 = SCL
//LiquidCrystal_I2C.h & oneWire.h are needed for the i2C_lcd
//----------------led-sigalisation-control--------------------------------------------------------------------
int led_red = 12;// turns red if the temperature is not at the desired temperature
int led_orange = 11;// turns on if the heating elements are active
int led_green = 10;// turns on if the temperature is at the desired temperature
//----------------Knobs-temperature-control-------------------------------------------------------------------
int knop_up = 7;//turns the temperature up
int knop_down = 6;//turns the temperature down
int knopStatus;//converts digital input to an integer value
int knopStatus1;//converts digital input to an integer value
//-----------------Relay-setup-----------------------------------------------------------------------
int relay_klep = 5;//drives the high power relay to open the electro mechanical switch 
int relay_heater = 4;//drives the high power relay to power the heating elements
// int relay_ventilator = 3;//drives the high power relay to turn on the ventilator
int relay_groep = 3;//drives the high power relay to turn on the high power cooling station 
//-----------------Real-Time-Clock-DS3231----------------------------------------------------------------------

int onhour = 7;//turns on the heating elements at 7:30 am
int offhour = 8;//turns off the heating element at 8:00 am
int onhour1 = 19;//turns on the heating elements at 7:30 pm
int offhour1 = 20;//turns off the heating element at 8:00 pm
int offmin = 30;//turns on the heating elements at 7:30 am
int onmin = 0;//turns off the heating element at 8:00 am
int offmin1 = 30;//turns on the heating elements at 7:30 pm
int onmin1 = 0;;//turns off the heating elements at 8:00 Pm
//set the desired time here to turn the on the heater (7:30-8:00) && (19:30-20:00)
void setup() 
{

//prevents the relays for turning on due to floating voltages

//----------------Main-setup-for-IO-ports--------------------------------------------------------------
   Serial.begin(9600);//set the serial communication Baud rate to 9600
  //which is fast enough for all the serial communication
//----------------Real-Time-Clock-DS3231----------------------------------------------------------------------
  rtc.begin();//starts the I2C communication between the arduino and RTC 

//----------------I2C-LCD-Setup------------------------------------------------------------------------------- 
  lcd.begin(20,4,LCD_5x8DOTS);//turns on the connection to the 20X4 i2c_lcd
  lcd.init();//writes the lcd empty
  lcd.backlight();//sets the lcd backlight on
  lcd.setCursor (0,0);//sets the cursor
  lcd.print ("Raphael Cochez");//display this text
  lcd.setCursor (0,1);//sets the cursor
  lcd.print ("Cooling V3");//display this text
  lcd.setCursor (0,2);//sets the cursor
  lcd.print ("Kast 1");//display this text
  delay(10000);//adds a little delay for the startscreen
  //also allows the DS18B20 to start measuring more accurate 
  lcd.init ();//writes the lcd empty
//----------------DS18B20-temperature-sensor-setup------------------------------------------------------------ 
  sensors.begin();//turns on the DS18B20
//----------------Led-signalisation-setup---------------------------------------------------------------------
  pinMode(led_red, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(led_orange, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(led_green, OUTPUT);// set the digital pin to disable the pullup resistor 
//----------------Knobs-temperature-control-setup-------------------------------------------------------------  
  pinMode(knop_up, INPUT);// set the digital pin to enable the pullup resistor 
  pinMode(knop_down, INPUT); // set the digital pin to enable the pullup resistor 
//----------------Relay-drivers-setup-------------------------------------------------------------------------  
//pinMode(relay_ventilator,OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_klep, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_heater, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_groep, OUTPUT);// set the digital pin to disable the pullup resistor 
  digitalWrite(relay_klep,LOW);
  digitalWrite(relay_heater, LOW);
  digitalWrite(relay_groep,LOW);
//----------------serial-communication-setup------------------------------------------------------------------  

  Serial.setTimeout(10);//times out the serial communication for a 1/600 of a second
  //enables smoother serial cummunication
}

void loop()
{
//---------------DS18B20-temperature-read-and-serial-monitor-displaying---------------------------------------
  sensors.requestTemperatures();// send the command to get temperatures
  tempCelsius = sensors.getTempCByIndex(0);// read temperature in Celsius
  Serial.print("Temperature: ");//display this text in the serial monitor
  Serial.print(tempCelsius);// print the temperature in Celsius
  Serial.print("°C");//display this text in the serial monitor

//--------------Real-Time-Clock-D3231-time-request-and-serial-communication-----------------------------------
    t = rtc.getTime();
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  delay (100);
//--------------Knobs-read-input-and-sets-the-desired-temperature---------------------------------------------
  knopStatus  = digitalRead (knop_up);
  knopStatus1 = digitalRead (knop_down);
  
if (knopStatus == HIGH)//if this value is high the desired temperature is changed +1 
  {
    setTemp ++;
    Serial.println(" SetTemp ++");
  }
if (knopStatus1 == HIGH)//if this value is high the desired temperature is changed -1 
  {
    setTemp --; 
    Serial.println(" setTemp -- ");
  }
//-------------Displaying-which-instalation-we-are-working-with-on-the-lcd------------------------------------ 
    lcd.setCursor(0, 0);
    lcd.print("Kast 1 ");
//------------Displaying-the-DS18B20-sensor-measured-value-on-the-lcd-----------------------------------------
  
    lcd.setCursor(0, 2);
    lcd.print("sensor: ");
    lcd.print (tempCelsius);
    lcd.print(" C");
//------------Displaying-the-desired-temperature-on-the-lcd---------------------------------------------------
    lcd.setCursor(0, 3);
    lcd.print("Set Temp: ");
    lcd.print (setTemp);
    lcd.print(" C ");
//------------Displaying-the-desired-temperature-on-the-lcd---------------------------------------------------
    lcd.setCursor(15, 0);
    lcd.print(t.hour);
    lcd.print (":");
    lcd.print (t.min);
    
delay (100);//delay gives code room to breath

  

if(t.hour == onhour && (t.min == onmin))
 {
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (led_red, LOW);//turns off the fault signal because its in heating mode
  digitalWrite (led_green, LOW);//turns on the green led to indicate that the temperature is ok
  delay(60000); //gives the system time to reset
  digitalWrite (relay_heater, HIGH);//turns on the heater
 
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok  

   
 }
    
if(t.hour == offhour &&(t.min == offmin))
 {
  
if (tempCelsius > setTemp )
//checks if there is no change in desired temperature
//compares the measured temperature with the desired temperature
{
//control of the relays 
  digitalWrite (relay_groep, LOW);//turns on the cooling plant
  digitalWrite (relay_klep, LOW);//turns on the electro mechanical switch
  digitalWrite (relay_heater, HIGH);//turns of the heater to make sure its off
  digitalWrite (led_green, LOW);//indicates that the temperature is not ok
  digitalWrite (led_orange, LOW);//indicates that the heater is off
//red led blinks 5 times to signal a to high measured temperature after that it stays high for 25 seconds 
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red,HIGH);//turns on the led to give the indicator that the temperature is not ok  
 }
if (tempCelsius <= setTemp)
{
//control of the relays 
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (relay_heater, LOW);////turns of the heater to make sure its off
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, HIGH);//turns on the green led to indicate that the temperature is ok
  digitalWrite (led_orange, LOW); //indicates that the heater is off
  delay (60000);  
 }
//------------------------second-part---------------------------------------------------------------------------
if(t.hour == onhour1 && (t.min == onmin1))
 {
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, LOW);//turns on the green led to indicate that the temperature is ok
  delay(60000); //gives the system time to reset
  digitalWrite (relay_heater, HIGH);//turns on the heater
 
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_orange, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok     
 }
if(t.hour == offhour1 && (t.min == offmin1))
 {
  
digitalWrite (relay_heater, LOW);//turns of the heater to make sure its off
delay(60000);//gives the system time to reset

if (tempCelsius > setTemp )
//checks if there is no change in desired temperature
//compares the measured temperature with the desired temperature
{
//control of the relays 
  digitalWrite (relay_groep, HIGH);//turns on the cooling plant
  digitalWrite (relay_klep, HIGH);//turns on the electro mechanical switch
  digitalWrite (relay_heater, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, LOW);//indicates that the temperature is not ok
  digitalWrite (led_orange, LOW);//indicates that the heater is off
//red led blinks 5 times to signal a to high measured temperature after that it stays high for 25 seconds 
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
      delay (1000); 
  digitalWrite (led_red, LOW);//turns off the led shortly
      delay (1000);
  digitalWrite (led_red,HIGH);//turns on the led to give the indicator that the temperature is not ok  
 }
if (tempCelsius <= setTemp)
{
//control of the relays 
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (relay_heater, LOW);////turns of the heater to make sure its off
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, HIGH);//turns on the green led to indicate that the temperature is ok
  digitalWrite (led_orange, LOW); //indicates that the heater is off
  delay (60000);

  
} 
}
}
}

The issues i encounter:

  1. The relays wont receive any signal using this code but i can't find out why.
  2. The code doesn't seems to compare the measured signal with the desired signal
  3. I encounter floating voltages on the relays which is why i tried to write the internal pullup
    resistor to make sure its an input and a low output state

Things i tried to fix my problem:

  1. With a regular testcode* on pin 3, 4, 5 the relays work fine so there is no fault in the wiring
  2. The DS18B20 is working fine and displays its value on the serial monitor as well on the I2C LCD
  3. The integer to set the desired temperature is also working and displays its value on the serial
    monitor as well on the I2C LCD to.
  4. i tried to write my used pins 3, 4, 5 active LOW in the setup

Can i get some help with this issue? I am breaking my mind over this stuff.
I don't think there is a wiring problem because when testing al different parts separately they work fine.
my guess is there is something wrong with the DS3231 parts of the code or there is some minor mistake which i completely overlooked.

testcode*

int button1 = 6;
int button2 = 7;
int knopState1;
int knopState2;
int relay1 = 3;
int relay2= 4;
int relay3 = 5;
void setup() {
  // put your setup code here, to run once:
Serial.begin (9600);
pinMode(knop1, INPUT);
pinMode(knop2, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
knopState1 = digitalRead (button1);
knopState2 = digitalRead (button2);
if (knopstate1 == HIGH)
{
  Serial.println ("button ok");
  digitalWrite (relay1, HIGH);
  delay (800);
  digitalWrite (relay2, LOW);
  delay (800);
  digitalWrite (relay3, LOW);
  delay (800);
  Serial.println ("relay 1 works");

}
if (knopState2 == HIGH)
{
  Serial.println ("button 2 ok");
  digitalWrite (relay1, LOW);
  delay (800);
  digitalWrite (relay2, HIGH);
  delay (800);
  digitalWrite (relay3, HIGH);
  delay (800);
  Serial.println ("relay2 & relay3 works$");

}
}

Hello
The amount of used delay()´s will bring your sketch to sleep.
The sketch needs some timers based one the BWOD example to be found inside the IDE and you may shall study the IPO model to make a redsign of your project.

	Line 73:   delay(10000);//adds a little delay for the startscreen
	Line 73:   delay(10000);//adds a little delay for the startscreen
	Line 115:   delay (100);
	Line 150: delay (100);//delay gives code room to breath
	Line 150: delay (100);//delay gives code room to breath
	Line 160:   delay(60000); //gives the system time to reset
	Line 164:       delay (1000); 
	Line 166:       delay (1000);
	Line 168:       delay (1000); 
	Line 170:       delay (1000);
	Line 172:       delay (1000); 
	Line 174:       delay (1000);
	Line 195:       delay (1000); 
	Line 197:       delay (1000);
	Line 199:       delay (1000); 
	Line 201:       delay (1000);
	Line 203:       delay (1000); 
	Line 205:       delay (1000);
	Line 217:   delay (60000);  
	Line 226:   delay(60000); //gives the system time to reset
	Line 230:       delay (1000); 
	Line 232:       delay (1000);
	Line 234:       delay (1000); 
	Line 236:       delay (1000);
	Line 238:       delay (1000); 
	Line 240:       delay (1000);
	Line 247: delay(60000);//gives the system time to reset
	Line 261:       delay (1000); 
	Line 263:       delay (1000);
	Line 265:       delay (1000); 
	Line 267:       delay (1000);
	Line 269:       delay (1000); 
	Line 271:       delay (1000);
	Line 283:   delay (60000);

Hi there @paulpaulson

Thanks for the reply, changing the amount of delays by the BWOD method did seem to fix the DS18B20 not compare its signal with the setTemp integer.

For some reason all the relays are now in a always on state?
Do you have an idea how that's happening?

// edited code

#include <DS3231.h>////real time clock libary
#include <OneWire.h>//sensor communication libary
#include <LiquidCrystal_I2C.h>//i2c_lcd libary
#include <DallasTemperature.h>//DS18B20 temperature sensor libary
//----------------BWOD-test--------------------------------------------------
const unsigned long eventInterval1 = 1000;
const unsigned long eventInterval2 = 10000;
const unsigned long eventInterval3 = 60000;
unsigned long previousTime = 0;
//----------------Libaries-setup-------------------------------------------------------------------------------
//----------------I2C-Real-Time-Clock-D3231-setup--------------------------------------------------------------
DS3231  rtc(SDA, SCL);
Time t;
// ---------------DS18B20-temperature-sensor-setup-------------------------------------------------------------
int SensorDataPin = 2;//datapin for the sensor this cannot be changed because of the DellasTemperature libary
OneWire oneWire(SensorDataPin);//onewire setup 
DallasTemperature sensors(&oneWire); //onewire setup 
float tempCelsius;// the value of the measured temperature in celcius
//arduino D2 is the sensor pin
//DellasTemperature.h is the libary needed for the DS18B20
int setTemp = -10; //default temperature = -10 degrees celcius this is adjustable to any temperature. 
// Note that how higher the temperature is the more the relais have to switch 
// temperature cannot be set lower than -30 this is because of the cooling plant limitations
// on the lcd screen it is possible to do but not relaiable
//----------------I2C-LCD-20X4-setup--------------------------------------------------------------------------
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x03F, 20, 4);
//arduino nano analog pin 4 = SDA
//arduino nano analog pin 5 = SCL
//LiquidCrystal_I2C.h & oneWire.h are needed for the i2C_lcd
//----------------led-sigalisation-control--------------------------------------------------------------------
int led_red = 12;// turns red if the temperature is not at the desired temperature
int led_orange = 11;// turns on if the heating elements are active
int led_green = 10;// turns on if the temperature is at the desired temperature
//----------------Knobs-temperature-control-------------------------------------------------------------------
int knop_up = 7;//turns the temperature up
int knop_down = 6;//turns the temperature down
int knopStatus;//converts digital input to an integer value
int knopStatus1;//converts digital input to an integer value
//-----------------Relay-setup-----------------------------------------------------------------------
int relay_klep = 5;//drives the high power relay to open the electro mechanical switch 
int relay_heater = 4;//drives the high power relay to power the heating elements
// int relay_ventilator = 3;//drives the high power relay to turn on the ventilator
int relay_groep = 3;//drives the high power relay to turn on the high power cooling station 
//-----------------Real-Time-Clock-DS3231----------------------------------------------------------------------

int onhour = 7;//turns on the heating elements at 7:30 am
int offhour = 8;//turns off the heating element at 8:00 am
int onhour1 = 19;//turns on the heating elements at 7:30 pm
int offhour1 = 20;//turns off the heating element at 8:00 pm
int offmin = 30;//turns on the heating elements at 7:30 am
int onmin = 0;//turns off the heating element at 8:00 am
int offmin1 = 30;//turns on the heating elements at 7:30 pm
int onmin1 = 0;;//turns off the heating elements at 8:00 Pm
//set the desired time here to turn the on the heater (7:30-8:00) && (19:30-20:00)
void setup() 
{

//BWOD-test------------


//----------------Main-setup-for-IO-ports--------------------------------------------------------------
   Serial.begin(9600);//set the serial communication Baud rate to 9600
  //which is fast enough for all the serial communication
//----------------Real-Time-Clock-DS3231----------------------------------------------------------------------
  rtc.begin();//starts the I2C communication between the arduino and RTC 

//----------------I2C-LCD-Setup------------------------------------------------------------------------------- 
  lcd.begin(20,4,LCD_5x8DOTS);//turns on the connection to the 20X4 i2c_lcd
  lcd.init();//writes the lcd empty
  lcd.backlight();//sets the lcd backlight on
 
 
  lcd.setCursor (0,0);//sets the cursor
  lcd.print ("Raphael Cochez");//display this text
  lcd.setCursor (0,1);//sets the cursor
  lcd.print ("Cooling V3");//display this text
  lcd.setCursor (0,2);//sets the cursor
  lcd.print ("Kast 1");//display this text
  delay (10000);
  
 //test the BWOD method 
 
  //also allows the DS18B20 to start measuring more accurate 
  lcd.init ();//writes the lcd empty
//----------------DS18B20-temperature-sensor-setup------------------------------------------------------------ 
  sensors.begin();//turns on the DS18B20
//----------------Led-signalisation-setup---------------------------------------------------------------------
  pinMode(led_red, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(led_orange, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(led_green, OUTPUT);// set the digital pin to disable the pullup resistor 
//----------------Knobs-temperature-control-setup-------------------------------------------------------------  
  pinMode(knop_up, INPUT);// set the digital pin to enable the pullup resistor 
  pinMode(knop_down, INPUT); // set the digital pin to enable the pullup resistor 
//----------------Relay-drivers-setup-------------------------------------------------------------------------  
//pinMode(relay_ventilator,OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_klep, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_heater, OUTPUT);// set the digital pin to disable the pullup resistor 
  pinMode(relay_groep, OUTPUT);// set the digital pin to disable the pullup resistor 
//----------------serial-communication-setup------------------------------------------------------------------  

  Serial.setTimeout(10);//times out the serial communication for a 1/600 of a second
  //enables smoother serial cummunication
}

void loop()
{
unsigned long currentTime = millis();

//---------------DS18B20-temperature-read-and-serial-monitor-displaying---------------------------------------
  sensors.requestTemperatures();// send the command to get temperatures
  tempCelsius = sensors.getTempCByIndex(0);// read temperature in Celsius
  Serial.print("Temperature: ");//display this text in the serial monitor
  Serial.print(tempCelsius);// print the temperature in Celsius
  Serial.print("°C");//display this text in the serial monitor

//--------------Real-Time-Clock-D3231-time-request-and-serial-communication-----------------------------------
    t = rtc.getTime();
if (currentTime - previousTime >= eventInterval1)
{    
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  previousTime = currentTime;
}
  
//--------------Knobs-read-input-and-sets-the-desired-temperature---------------------------------------------
  knopStatus  = digitalRead (knop_up);
  knopStatus1 = digitalRead (knop_down);
  
if (knopStatus == HIGH)//if this value is high the desired temperature is changed +1 
  {
    setTemp ++;
    Serial.println(" SetTemp ++");
  }
if (knopStatus1 == HIGH)//if this value is high the desired temperature is changed -1 
  {
    setTemp --; 
    Serial.println(" setTemp -- ");
  }
//-------------Displaying-which-instalation-we-are-working-with-on-the-lcd------------------------------------ 
    lcd.setCursor(0, 0);
    lcd.print("Kast 1 ");
//------------Displaying-the-DS18B20-sensor-measured-value-on-the-lcd-----------------------------------------
  
    lcd.setCursor(0, 2);
    lcd.print("sensor: ");
    lcd.print (tempCelsius);
    lcd.print(" C");
//------------Displaying-the-desired-temperature-on-the-lcd---------------------------------------------------
    lcd.setCursor(0, 3);
    lcd.print("Set Temp: ");
    lcd.print (setTemp);
    lcd.print(" C ");
//------------Displaying-the-desired-temperature-on-the-lcd---------------------------------------------------
    lcd.setCursor(15, 0);
    lcd.print(t.hour);
    lcd.print (":");
    lcd.print (t.min);
    
//(edit)deleted the delay

  

if(t.hour == onhour && (t.min == onmin))
 {
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (led_red, LOW);//turns off the fault signal because its in heating mode
  digitalWrite (led_green, LOW);//turns on the green led to indicate that the temperature is ok
 if (currentTime - previousTime >= eventInterval3)
  { 
  digitalWrite (relay_heater, HIGH);//turns on the heater
 
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok
  previousTime = currentTime;
  }
 }    
if(t.hour == offhour &&(t.min == offmin))
 {
  
if (tempCelsius > setTemp )
//checks if there is no change in desired temperature
//compares the measured temperature with the desired temperature
{
//control of the relays 
  digitalWrite (relay_groep, HIGH);//turns on the cooling plant
  digitalWrite (relay_klep, HIGH);//turns on the electro mechanical switch
  digitalWrite (led_green, LOW);//indicates that the temperature is not ok
  digitalWrite (led_orange, LOW);//indicates that the heater is off
  digitalWrite (relay_heater, LOW);//turns of the heater to make sure its off
 
//red led blinks 5 times to signal a to high measured temperature after that it stays high for 25 seconds 
  digitalWrite (led_red,HIGH);//turns on the led to give the indicator that the temperature is not ok  
//(edit)deleted the delays
 }
if (tempCelsius <= setTemp)
{
 if (currentTime - previousTime >= eventInterval3)
 {
//control of the relays 
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (relay_heater, LOW);////turns of the heater to make sure its off
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, HIGH);//turns on the green led to indicate that the temperature is ok
  digitalWrite (led_orange, LOW); //indicates that the heater is off
  
 previousTime = currentTime;
  
 }
}

//------------------------second-part---------------------------------------------------------------------------

if(t.hour == onhour1 && (t.min == onmin1))
 {
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, LOW);//turns on the green led to indicate that the temperature is ok
  if (currentTime - previousTime >= eventInterval3)
  {
  digitalWrite (relay_heater, HIGH);//turns on the heater
 
  digitalWrite (led_orange, HIGH);//turns on the led to give the indicator that the temperature is not ok   
 //(edit)deleted the delays
  }
 }
if(t.hour == offhour1 && (t.min == offmin1))
 {
  
digitalWrite (relay_heater, LOW);//turns of the heater to make sure its off



if (tempCelsius > setTemp )
//checks if there is no change in desired temperature
//compares the measured temperature with the desired temperature
{
//control of the relays 
  digitalWrite (relay_groep, HIGH);//turns on the cooling plant
  digitalWrite (relay_klep, HIGH);//turns on the electro mechanical switch
  digitalWrite (relay_heater, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, LOW);//indicates that the temperature is not ok
  digitalWrite (led_orange, LOW);//indicates that the heater is off
  digitalWrite (led_red, HIGH);//turns on the led to give the indicator that the temperature is not ok
  //(edit)deleted the delays
 }
 
if (tempCelsius <= setTemp)
{
//control of the relays 
if (currentTime - previousTime >= eventInterval3)
{
  digitalWrite (relay_groep, LOW);//turns off the cooling plant
  digitalWrite (relay_klep,  LOW);//turns off the electro mechanical switch
  digitalWrite (relay_heater, LOW);////turns of the heater to make sure its off
  digitalWrite (led_red, LOW);//turns of the heater to make sure its off
  digitalWrite (led_green, HIGH);//turns on the green led to indicate that the temperature is ok
  digitalWrite (led_orange, LOW); //indicates that the heater is off
  
}
  
} 
}

}
}

Hello
The sketch needs a time function reading the temperature once per second.
As I rememer the DS18B20 will block the sketch when a fine temperature resoltion is used.

A small code improvement you might want to make or not.

Can you write a test sketch that energizes one relay?

Do you have 10k pulldown resistors connected from button input pins to GND?
Is your relay board the active LOW type? Post a link.

hi,
i do not have 10K pulldown resistors to ground. i use 270 ohms resistors from signal to ground instead instead.
breadboard_working_with_a_push_button_CPcExAtPa6 (2)

and i use this relay module:

(Arduino forum doesnt allow me to opload this picture so ill give the link instead)

i do think its an Active low type yes
many thanks

yes, while runing the testcode* which i wrote below in the original post it works just as intended.

I'll try it right now.

I ask because your code says [quote="raphael_cochez, post:3, topic:900640"]

digitalWrite (relay_groep, HIGH);//turns on the cooling plant
  digitalWrite (relay_klep, HIGH);//turns on the electro mechanical switch

Are your loads connected to the NC relay terminal (backwards)?

No they are connected to the NO terminals. i got the feeling it has something to do with floating voltages or with the DS3231 code.

i used this code as example:

#include <DS3231.h>

int Relay = 4;

DS3231  rtc(SDA, SCL);
Time t;

const int OnHour = 12;
const int OnMin = 24;
const int OffHour = 12;
const int OffMin = 25;

void setup() {
  Serial.begin(115200);
  rtc.begin();
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);
}

void loop() {
  t = rtc.getTime();
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  delay (1000);
  
  if(t.hour == OnHour && t.min == OnMin){
    digitalWrite(Relay,HIGH);
    Serial.println("LIGHT ON");
    }
    
    else if(t.hour == OffHour && t.min == OffMin){
      digitalWrite(Relay,LOW);
      Serial.println("LIGHT OFF");
    }
}

No, you schedule a conversion, and later go and read the value - the calls are non-blocking in the common libraries to my knowledge - of course you can just use a delay (750) in simple use-cases, but you aren't forced to.

My understanding is that you have options.

Read the DS18B20 now.
It reports the value from the last reading.
Disconnects. Then after it disconnect it takes a new reading. Ready for yhe next request.

To data transfer is rapid.

The other way is to ask it to take a reading and you wait for it. Up to 0.75 mS

Most use the first method.
Some signal the DS18B20 to take a reading . Then do other stuff in loop() and come back 0.75mS or more and retrieve that reading.