Now that the ESP32 talks to Blynk, let's make it useful. The DHT11 module measures temperature and humidity, the ESP32 sends both to the app every five seconds, and Blynk keeps a history so you can see how your room changes during the day. When it gets too hot, your phone gets a notification, and you set the limit with a slider in the app.
What you'll learn
- How to send decimal numbers to Blynk
- How to set a limit from the app with a slider
- How to send push notifications with Blynk events
- How hysteresis stops a notification from repeating
What you need
- ESP32 board, expansion board and USB cable (ESP32 IoT Starter Kit)
- DHT11 temperature and humidity module (45-in-1 Sensor Kit)
- 1 red LED and 1 resistor, 220 Ω (ESP32 IoT Starter Kit)
- Breadboard and jumper wires (ESP32 IoT Starter Kit)
- A free Blynk account and the Blynk IoT app on a phone
- A 2.4 GHz Wi-Fi network
Wiring

| From | To |
|---|---|
| DHT11 module S | ESP32 GPIO 27 |
| DHT11 module + | 3V3 |
| DHT11 module − | GND |
| ESP32 GPIO 26 | 220 Ω resistor, then the LED's long leg |
| LED short leg | GND |
Sensor modules from different makers can label and order their pins differently. Always follow the labels printed on your module.
Set up Blynk
In the Blynk console, create a new template called Climate station (hardware ESP32, connection type Wi-Fi) and add these datastreams. Lesson 1 shows each step in detail.
| Virtual pin | Name | Data type | Range | Phone widget |
|---|---|---|---|---|
| V0 | Temperature | Double | 0 – 50, units °C | Gauge and Chart |
| V1 | Humidity | Double | 0 – 100, units % | Gauge |
| V2 | Hot limit | Integer | 15 – 40, units °C | Slider |
Then open the template's Events & Notifications tab, add an event with the code too_hot (name: Too hot) and turn on push notifications for it. The event code must match the sketch exactly.
Save the template, create a new device from it and copy its three BLYNK_… lines. In the phone app, open the device, tap the wrench icon and add two Gauges (V0, V1), a Slider (V2) and a Chart showing V0 and V1. Link each widget to its datastream.

The sketch
You also need the DHT sensor library (by Adafruit) from the DHT11 lesson.
Replace the three BLYNK_… lines at the top with the ones from your device's Device info page, and add your Wi-Fi name and password (2.4 GHz only). The BLYNK_… lines must stay above #include <BlynkSimpleEsp32.h>.
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "Climate station"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
#define BLYNK_PRINT Serial // show connection messages in the Serial Monitor
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";
const int DHT_PIN = 27;
const int LED_PIN = 26;
DHT dht(DHT_PIN, DHT11);
BlynkTimer timer;
int hotLimit = 28; // changed from the app (V2)
bool alertSent = false;
BLYNK_WRITE(V2) {
hotLimit = param.asInt();
Serial.print("New limit: ");
Serial.println(hotLimit);
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V2); // get the slider's value after a restart
}
void readClimate() {
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
if (isnan(temp) || isnan(humidity)) {
Serial.println("Couldn't read the DHT11");
return;
}
Blynk.virtualWrite(V0, temp);
Blynk.virtualWrite(V1, humidity);
bool hot = temp >= hotLimit;
digitalWrite(LED_PIN, hot);
if (hot && !alertSent) {
Blynk.logEvent("too_hot", "It's " + String(temp, 1) + " °C in the room");
alertSent = true;
}
if (temp < hotLimit - 1) alertSent = false; // ready again after cooling by 1 °C
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
dht.begin();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(5000L, readClimate); // every 5 seconds
}
void loop() {
Blynk.run();
timer.run();
}
To test the alert, set the slider a degree or two above the current temperature, then warm the sensor gently by holding it between your fingers. The LED lights and your phone shows "Too hot".
How it works
Blynk.logEvent() creates an event in the device's timeline, and because you turned on notifications for too_hot, Blynk also sends a push notification. Without alertSent you'd get a notification every five seconds while it's hot, and Blynk limits how many events a device can send per day. So the sketch sends one alert, then waits until the temperature has dropped at least 1 °C below the limit before it can alert again. This gap between "on" and "off" is called hysteresis, and real thermostats use it too.
Try this next
- Add a second event,
too_dry, for humidity under 30 %. - Show "Comfortable", "Too hot" or "Too humid" on a Value Display widget using a String datastream.
- Compare the DHT11 with the DS18B20 module from the Sensor Kit, which is more precise.
Troubleshooting
-
The device shows "Offline" in the app: check the Serial Monitor at 115200 baud. "Invalid auth token" means the
BLYNK_AUTH_TOKENline is wrong; if it never connects, check the Wi-Fi name and password, and that your network is 2.4 GHz. - "Couldn't read the DHT11": check that S is on GPIO 27 and that + and − aren't swapped. The DHT11 can only be read about once per second.
-
No notification arrives: check that the event code is exactly
too_hot, notifications are on for the event, and the Blynk app is allowed to send notifications on your phone. - The chart is empty: it needs a few minutes of data. Some chart ranges depend on your Blynk plan; the gauges always work.