From 437ea74c1741028a6fadf11f02f0ceece6a567d9 Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Fri, 11 Oct 2024 20:52:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B3=D1=80=D0=B5?= =?UTF-8?q?=D0=B2=20=D1=80=D0=B5=D0=BB=D0=B5=20=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B0=D0=B3=D1=80=D0=B5=D0=B2,=20?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B5=20=D1=81=D0=B1=D1=80=D0=B0=D1=81=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D0=B5=D1=82=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- heater_v3.ino | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/heater_v3.ino b/heater_v3.ino index 95d2ac3..c8ca835 100644 --- a/heater_v3.ino +++ b/heater_v3.ino @@ -32,6 +32,8 @@ DHT dht(DHTPIN, DHTTYPE); // deviation from target t allowed (in degrees multiplied by 100) #define T_HYSTERESIS 150 +// relay cooldown temperature (after what t we allow to turn on relay again) (in degrees multiplied by 100) +#define RELAY_COOLDOWN_T 500 // timeout to switch from external to internal temperature data (in milliseconds) #define SWITCH_TO_INTERNAL_TIMEOUT 50000 @@ -287,7 +289,6 @@ void loop() { cur_state = 1; } - else if (current_t > target_t + T_HYSTERESIS) { cur_state = 0; @@ -297,14 +298,22 @@ void loop() { cur_state = override_state; } - if (relay_t > CRITICAL_T) - { - //Serial.printf("Critical overheat, t = %d\n", relay_t); - cur_state = 0; - overheat = 1; - } - else overheat = 0; - digitalWrite(RELAY_PIN, cur_state); + if (!overheat) + { + if (relay_t > CRITICAL_T) + { + overheat = 1; + } + } + else + { + if (relay_t < CRITICAL_T - RELAY_COOLDOWN_T) + { + overheat = 0; + } + } + if (cur_state && !overheat) digitalWrite(RELAY_PIN, 1); + else digitalWrite(RELAY_PIN, 0); if (u) { Serial.printf("State %d Relay t %d Internal t %d External t %d Current t %d Target t %d\n", cur_state, relay_t, internal_t, external_t, current_t, target_t);