I am creating an automatic window Opener that uses 2 DS1820 digital temperature sensors. I have them hooked up to the Arduino so that when the difference in temperatures is at a certain level, it will open or close a window depending on the state of the window. My problem is that when the indoor temperature is below 70 and the outdoor is above 70, the motor opens and then closes immediately, continuously. It's an endless cycle of open and close. If the indoor temperature is above 70 and the outdoor is below, then it opens the window properly like it's supposed to. Here is my temperature test function.
The issue is that when the else if statement is true, it keeps opening and closing a window over and over again. MotorPinC stands for the motor closing the window. MotorPinO stands for Opening the window.
The Open and Close are to signify if the window is already opened or closed.
I think one thing that might help is have a wider threshold, not unlike a furnace's thermostat. Therefore, don't attempt to actuate window until temps are < 68 and > 72 indoors. It seems as though the problem exists when temp is exactly 70 wherein in >= 70 and out <= 70 both qualify.