Part 3— Analog Compare
This logic symbol takes two analog input values, and if the first one is equal to, or higher than the second one, then the digital output will be 1 (high). On the other hand if the first input value is lower than the second input value, then the digital output will be 0 (low).
For example:
So if the value of current_temp is equal to, or higher than the value of your temp_threshold, then turn on the aircon, however if the current_temp stays lower than the threshold then turn the aircon off.
So let’s say the room gets to 25 degrees, and you’d set your temp threshold to be 25 degrees, then the room is too hot, so you want the aircon to switch on…..as the room cools down and drops below 24 degrees, then automatically switch the aircon back off again.
So what’s the third option for?
Well this is used to prevent constant toggling of on and off by creating a buffer value. Let’s look at what might happen if you didn’t use it…. the room might get to 25 degrees so the aircon switches on….then aircon cools the room, so the temp drops down to 24 after a few minutes, so the aircon switches off….but then room gets hot again, so the aircon switches on….then room cools down so it switches off again, and this cycle keeps repeating which is probably not efficient.
The optional buffer allows you to effectively set a range in which the temperature will stay before the aircon switches off, rather than flip-flapping on and off.
So you could set it to be something like this…..
So in this scenario, the aircon will switch on as soon as the temperature reaches 22 degrees, but it won’t then suddenly switch back off again when the temp drops back below 22 degrees….it will in fact now stay on until the temp goes below 20 degrees. So basically the temp needs to get down to 19 degrees before it switches off….. and once it goes off and the room starts getting hot again, then it won’t back switch on until the room reaches 22 degrees. So we’ve created a 3-degree buffer zone between 19 degrees and 22 degrees.