I am newbie to arduino and c. I am working on a project in which I have a DHT11 and nodemcu esp8266. In this project I want to control an AC . Condition I want is Ac must turn on when temperature goes above 32.00 degree and stay on until temp goes below 30.00. After going below 30.00 degree AC should turn off and turn on only when temperature goes above 32.00 degree.
I am successfully turning ac on when it goes above 32.00 but it never turn off even if temp goes below 30.00. On resetting nodemcu it turns off.
I think my while loop is not breaking . Pasting my code below please help.
void loop() {
float t = dht.readTemperature();
if (t > 32.00) {
while (t > 30.00) {
float t = dht.readTemperature();
digitalWrite(r1,HIGH);
Serial.print(t);
Serial.println("Ac_on");
delay(1000);
}
}
else {
float t = dht.readTemperature();
digitalWrite(r1,LOW);
Serial.print(t);
Serial.println("Ac_off");
delay(1000);
}
}