Gabriel_swe:
No confusion at all. You are right in your assumption. If no criteria is met, relay status will stay as it was.I do see a possible unexpected behavior.
If t is 25 and h is 73, t wants to activate relay and h want to deactivate relay. Your h>72 statement comes first and is true and relay deactivates. If else is skipped.
Now if h falls to 72, if statement is false and then if else is executed. There t<28 is true and relay activates.
If your next reading of h is 73, relay will immediately deactivate.One solution to prevent frequent on/off is to use a counter and only activate/deactivate relay after x amount of subsequent readings.
Written in notepad, might contain spelling errors and other faults.byte relayLowCounter=0; //declare global, use int if more than ~4 minutes is needed.
byte relayHighCounter=0;
...
if (t > 32 || h > 72 ) {
//digitalWrite(Relay1, LOW);
relayLowCounter++;
relayHighCounter=0;
}
else if (t < 28 || h < 68 ) {
//digitalWrite(Relay1, HIGH);
relayHighCounter++;
relayLowCounter=0;
}
if (relayLowCounter>60){ // 60 for ~1 minute
digitalWrite(Relay1, LOW);
}
else if (relayHighCounter>60){
digitalWrite(Relay1, HIGH);
}
Hi, thank you, this was brought up in a previous post, this is why i gave a little gap between them. I will look more into it when my headache has gone, but my low is really high and my high is really low on the relay that i have, thou i think in what your saying it wont matter which way around which is, is that correct? Regards