if / else if

Trying to control the humidity level in a growing environment and also provide air exchange.
I use a Uno, a rtc DS3231, a DHT22 probe and 2 relays, 1 for ventilation, 1 for humidifying said ventilation.

I want vent/hum to run whenever humidity drops below setRh, but I also want ventilation to run from second 0 to second 30, humidity to run from second 15 to second 30.

The part with the probe works, but not the timed cycles. Timed cycles work on their own, but not when combined with the DHT22 part.

Not sure how to program it or what kind of loop to use to cram it all in. Here's the code:

if (mySensor.getHumidity() < setRH)
digitalWrite(FogRelay, LOW), digitalWrite(FanRelay, LOW);

else if (mySensor.getHumidity() > setRH)
digitalWrite(FogRelay, HIGH), digitalWrite(FanRelay, HIGH);

else if ((now.second()>=0) & (now.second()<=15))
digitalWrite(FanRelay,LOW),digitalWrite(FogRelay,HIGH);

else if((now.second() >=15)&&(now.second() <=30))
digitalWrite(FanRelay,LOW), digitalWrite(FogRelay, LOW);

else
digitalWrite(FanRelay,LOW),(digitalWrite(FogRelay, LOW));

Capture.JPG

(deleted)

Also you should store the result of "mySensor.getHumidity()" once in a variable, and test the variable.

Please read the sticky post at the top of the forum about how to properly post your sketch. It is much better to post the entire sketch, using code tags so you make it easier for people to help you.

I don't think you want all those if/else statements. Just set a flag based on the current humidity reading and then when testing the time, see if you need humidity or not. Also, you don't separate statements with a comma, you use a semicolon and enclose your entire if() inside curly braces

if (mySensor.getHumidity() < setRH) {
  needHumidity = true;
}
else {
  needHumidity = false;
}

// seconds will always be greater than or equal to 0 so why test?
if (now.second() <= 15 && needHumidity == true) {
  digitalWrite(FanRelay, LOW)
  digitalWrite(FogRelay, HIGH);
}

else if ((now.second() >= 15) && (now.second() <= 30) && needHumidity == true) {
  digitalWrite(FanRelay, LOW);
  digitalWrite(FogRelay, LOW);
}
else {
  digitalWrite(FanRelay, LOW);
  digitalWrite(FogRelay, LOW);
}