Running different code based on hour range rtc DS3231

This code works until I added a time range scope and it will compile but will not activate my relays as it originally did.

The first file is the original that works fine but I have to change the temperature parameters twice a day.

vent_control.ino.ino (1.24 KB)

hour_dependent_temp_control.ino (1.85 KB)

If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it’s ok to add it as an attachment.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

The automatic indentation of the Auto Format would make it obvious that all your if statement are nested. I don’t think this is what you wanted.

if  (((hour() <= 5) && (hour() >= 18)) && (MyFloatTemperature > 21.1)){  // true if time is between 6am and 5pm and temp above Hi daytime
if  (((hour() <= 5) && (hour() >= 18)) && (MyFloatTemperature < 17.7)){

These will never be true because there is no number that is less than or equal to 5 and also greater than or equal to 18.

This code worked until I added a time range scope and it will compile but will not activate my relays as it originally did.

Please Help

DS3231_Simple Clock;

int relayPin1 = 7; // co2 controller relay
int relayPin2 = 8; // fan controller relay

void setup()
{
Serial.begin(9600);
pinMode(relayPin1, OUTPUT); // sets the digital pin as output
pinMode(relayPin2, OUTPUT); // sets the digital pin as output
digitalWrite(relayPin1, HIGH); // Prevents relays from starting up engaged
digitalWrite(relayPin2, HIGH); // Prevents relays from starting up engaged
Clock.begin();

}

void loop()
{
byte MyIntegerTemperature;
float MyFloatTemperature;

Clock.read();
MyIntegerTemperature = Clock.getTemperature();
MyFloatTemperature = Clock.getTemperatureFloat();

if (((hour() >= 8) && (hour() <= 17)) && (MyFloatTemperature > 30)) { // true if time is between 6am and 5pm and temp above Hi daytime
digitalWrite(relayPin1, HIGH); // turns co2 off
digitalWrite(relayPin2, LOW); // turns fan on
if (((hour() >= 8) && (hour() <= 17)) && (MyFloatTemperature < 28)) {
digitalWrite(relayPin1, LOW); // turns co2 on
delay(20000); // delay for co2 burner ignite time
digitalWrite(relayPin2, HIGH); // turns fan off
if (((hour() <= 7) && (MyFloatTemperature > 22))) // true if time is between 6am and 5pm and temp above Hi daytime
digitalWrite(relayPin1, HIGH); // turns co2 off
digitalWrite(relayPin2, LOW); // turns fan on
if (((hour() <= 7) && (hour() >= 18)) && (MyFloatTemperature < 18)) {
digitalWrite(relayPin1, LOW); // turns co2 on
delay(20000); // delay for co2 burner ignite time
digitalWrite(relayPin2, HIGH); // turns fan off
if (((hour() >= 18)) && (MyFloatTemperature > 22)) { // true if time is between 6am and 5pm and temp above Hi daytime
digitalWrite(relayPin1, HIGH); // turns co2 off
digitalWrite(relayPin2, LOW); // turns fan on
if (((hour() >= 18)) && (MyFloatTemperature < 18)) {
digitalWrite(relayPin1, LOW); // turns co2 on
delay(20000); // delay for co2 burner ignite time
digitalWrite(relayPin2, HIGH); // turns fan off
}

// print the analog value:
Serial.println(“Temperature”);
Serial.println(MyFloatTemperature);

delay(10000); // delay in between reads for stability
}
}
}
}
}

Use CTRL T to format the sketch. Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code]

.

Does Serial.print() the time of day work OK.

.

The time is programmed and it will give me the time.

@Arduino49935, do not cross-post. Threads merged.