Gabriel_swe:
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.
Well it worked great, now do i still need a gap in the values of t & h, where it was
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);
}
could these values be the same like this now?
if (t > 30 || h > 70 ) {
//digitalWrite(Relay1, LOW);
relayLowCounter++;
relayHighCounter=0;
}
else if (t < 30 || h < 70 ) {
//digitalWrite(Relay1, HIGH);
relayHighCounter++;
relayLowCounter=0;
}
if (relayLowCounter>60){ // 60 for ~1 minute
digitalWrite(Relay1, LOW);
}
else if (relayHighCounter>60){
digitalWrite(Relay1, HIGH);
}
so i've changed it too <30 or >30 or am i best still leaving it like <28 or > 32?
One more thing, if i was to add another relay and used the same
byte relayLowCounter=0;
am i right in thinking the '60' stated for length of time will also have to be the same for if i was to add a Relay2, and if i wanted it different would i need to do this
byte relayLowCounter1=0;
Note i added a 1 at the end of byte relayLowCounter?
Regards