|
ESP32-Smart-Thermostat-Blynk-APP
|
ESP32 Smart Thermostat with TFT Display and Blynk Integration. More...
#include <WiFi.h>#include <WiFiClient.h>#include <BlynkSimpleEsp32.h>#include <TFT_eSPI.h>#include <DHT.h>Macros | |
| #define | BLYNK_TEMPLATE_ID "TMPLxxxxxxxxx" |
| #define | BLYNK_TEMPLATE_NAME "My Thermostat" |
| #define | BLYNK_AUTH_TOKEN "AbCdEfGhIjKlMnOpQrStUvWxYz123456" |
| #define | RELAY_PIN 26 |
| #define | SENSOR_PIN 15 |
| #define | SENSOR_TYPE DHT11 |
| #define | BACKLIGHT_PIN 13 |
| #define | RELAY_ON LOW |
| Relay Logic configuration. CW-020 Relays are usually Low-Level Trigger, meaning pulling the pin to GND turns the relay ON. | |
| #define | RELAY_OFF HIGH |
| #define | COLOR_PANEL_BG TFT_BLACK |
| #define | COLOR_PANEL_FROST 0x2104 |
| #define | COLOR_HEATING 0xFB00 |
| #define | COLOR_HUMIDITY 0x3DFF |
| #define | COLOR_GREY_TEXT 0x8410 |
| #define | COLOR_TEXT_WHITE TFT_WHITE |
Functions | |
| DHT | dht (SENSOR_PIN, SENSOR_TYPE) |
| BLYNK_WRITE (V2) | |
| Blynk App Callback: Target Temperature Slider. Triggered automatically when the user changes the slider on the Blynk App (Virtual Pin 2). | |
| BLYNK_WRITE (V4) | |
| Blynk App Callback: Emergency Stop Button. Forces the relay to turn off if the button on Virtual Pin 4 is pressed (value goes to 0). | |
| void | setup () |
| Standard Arduino Setup Function. Initializes hardware pins, display, sensors, and network connections. | |
| void | loop () |
| Standard Arduino Loop Function. Kept clean. Only processes Blynk cloud tasks and hardware timers. | |
| void | readSensorAndControl () |
| Core Application Logic. Reads the DHT sensor, applies calibration offsets, updates the cloud, checks the thermostat rules, and triggers a UI redraw if any data changed. | |
| void | checkThermostat () |
| Evaluates the current temperature against the target setpoint. Uses hysteresis to define a "deadband" so the relay doesn't rapidly click on and off when the temperature hovers exactly at the target. | |
| void | drawInterface () |
| Renders the Graphical User Interface on the TFT display. Draws the central circle, dynamic sidebar, icons, and text. | |
Variables | |
| char | ssid [] = "YOUR_WIFI_SSID" |
| char | pass [] = "YOUR_WIFI_PASSWORD" |
| TFT_eSPI | tft = TFT_eSPI() |
| BlynkTimer | timer |
| float | currentTemp = 0 |
| float | humidity = 0 |
| float | targetTemp = 22.0 |
| float | hysteresis = 0.5 |
| bool | isHeating = false |
| float | lastTemp = -999 |
| float | lastHumidity = -999 |
| float | lastTarget = -999 |
| bool | lastHeatingState = !isHeating |
| bool | forceRedraw = true |
| const unsigned char icon_drop[] | PROGMEM |
| XBM Image Data for the Humidity Drop. The PROGMEM keyword forces the microcontroller to store this array in Flash memory instead of RAM, leaving more RAM available for dynamic variables. | |
ESP32 Smart Thermostat with TFT Display and Blynk Integration.
| #define BACKLIGHT_PIN 13 |
| #define BLYNK_AUTH_TOKEN "AbCdEfGhIjKlMnOpQrStUvWxYz123456" |
| #define BLYNK_TEMPLATE_ID "TMPLxxxxxxxxx" |
| #define BLYNK_TEMPLATE_NAME "My Thermostat" |
| #define COLOR_GREY_TEXT 0x8410 |
| #define COLOR_HEATING 0xFB00 |
| #define COLOR_HUMIDITY 0x3DFF |
| #define COLOR_PANEL_BG TFT_BLACK |
| #define COLOR_PANEL_FROST 0x2104 |
| #define COLOR_TEXT_WHITE TFT_WHITE |
| #define RELAY_OFF HIGH |
| #define RELAY_ON LOW |
Relay Logic configuration. CW-020 Relays are usually Low-Level Trigger, meaning pulling the pin to GND turns the relay ON.
| #define RELAY_PIN 26 |
| #define SENSOR_PIN 15 |
| #define SENSOR_TYPE DHT11 |
| BLYNK_WRITE | ( | V2 | ) |
Blynk App Callback: Target Temperature Slider. Triggered automatically when the user changes the slider on the Blynk App (Virtual Pin 2).
| BLYNK_WRITE | ( | V4 | ) |
Blynk App Callback: Emergency Stop Button. Forces the relay to turn off if the button on Virtual Pin 4 is pressed (value goes to 0).
| void checkThermostat | ( | ) |
Evaluates the current temperature against the target setpoint. Uses hysteresis to define a "deadband" so the relay doesn't rapidly click on and off when the temperature hovers exactly at the target.
| DHT dht | ( | SENSOR_PIN | , |
| SENSOR_TYPE | ) |
| void drawInterface | ( | ) |
Renders the Graphical User Interface on the TFT display. Draws the central circle, dynamic sidebar, icons, and text.
| void loop | ( | ) |
Standard Arduino Loop Function. Kept clean. Only processes Blynk cloud tasks and hardware timers.
| void readSensorAndControl | ( | ) |
Core Application Logic. Reads the DHT sensor, applies calibration offsets, updates the cloud, checks the thermostat rules, and triggers a UI redraw if any data changed.
| void setup | ( | ) |
Standard Arduino Setup Function. Initializes hardware pins, display, sensors, and network connections.
| float currentTemp = 0 |
| bool forceRedraw = true |
Forces a full screen wipe and redraw on the first boot cycle
| float humidity = 0 |
| float hysteresis = 0.5 |
Temperature gap to prevent rapid relay switching
| bool isHeating = false |
| bool lastHeatingState = !isHeating |
| float lastHumidity = -999 |
| float lastTarget = -999 |
| float lastTemp = -999 |
| char pass[] = "YOUR_WIFI_PASSWORD" |
| const unsigned char icon_flame [] PROGMEM |
XBM Image Data for the Humidity Drop. The PROGMEM keyword forces the microcontroller to store this array in Flash memory instead of RAM, leaving more RAM available for dynamic variables.
XBM Image Data for the Heating Flame.
| char ssid[] = "YOUR_WIFI_SSID" |
| float targetTemp = 22.0 |
| TFT_eSPI tft = TFT_eSPI() |
| BlynkTimer timer |