
๐ IoT Smart Temperature & Humidity Monitor with ESP32 and Blynk
๐ 1. Introduction
This project demonstrates how to build a real-time environmental monitoring system that measures temperature and humidity using the DHT22 sensor and transmits the data to your smartphone using ESP32 and the Blynk IoT platform.
This system can be deployed in:
- Homes (for HVAC control),
- Greenhouses (climate regulation),
- Server rooms (to monitor heat and humidity),
- Warehouses (preserving temperature-sensitive items).
๐ฏ 2. Learning Objectives
By completing this project, you’ll gain hands-on experience with:
- Reading digital sensor data using GPIOs
- Configuring the ESP32 for Wi-Fi-based IoT communication
- Using Blynk to display sensor data on a mobile dashboard
- Wiring and testing a sensor circuit
- Debugging and improving real-time systems
๐งฐ 3. Tools and Components Needed
You’ll need the following hardware:
- One ESP32 development board
- One DHT22 (or AM2302) temperature & humidity sensor
- One 10kฮฉ resistor
- Breadboard and jumper wires
- Micro USB cable for uploading code and powering ESP32
And the following software/tools:
- Arduino IDE with ESP32 board support installed
- Blynk IoT app (available for iOS and Android โ Blynk 2.0 recommended)
- A registered Blynk account with your device added and tokens configured
- A stable Wi-Fi connection
๐ 4. Background Concepts
ESP32
A low-cost, low-power SoC microcontroller with dual-core CPU, integrated Wi-Fi, and Bluetooth. Ideal for IoT systems due to its networking and peripheral support.
DHT22
A digital sensor capable of measuring temperature and humidity with relatively high accuracy. It communicates via a single-wire protocol, making it easy to use with microcontrollers.
Blynk
An IoT cloud platform with a mobile app and web dashboard for controlling and monitoring hardware devices remotely. Offers virtual pins, device templates, data history, and alert features.
๐ ๏ธ 5. Step-by-Step Build Guide
Circuit Wiring Overview
- Connect the VCC pin of the DHT22 to the 3.3V pin of the ESP32.
- Connect the GND pin of the DHT22 to GND on the ESP32.
- Connect the Data pin of the DHT22 to GPIO 4 on the ESP32.
- Place a 10kฮฉ resistor between the Data pin and VCC (acts as a pull-up resistor for stable communication).
Circuit Description
ESP32 GPIO 4 --------> DHT22 Data
ESP32 3.3V --------> DHT22 VCC
ESP32 GND --------> DHT22 GND
(VCC to Data pull-up: 10kฮฉ resistor)
Programming the ESP32
- Install the Required Libraries:
- Install
DHT sensor library by Adafruitvia Arduino Library Manager - Install the latest
Blynklibrary (for Blynk 2.0+)
- Install
- Set up your Blynk device:
- Go to Blynk Console
- Create a new template (name it e.g., ESP32 DHT Monitor)
- Add two virtual pins: V0 (Temperature), V1 (Humidity)
- Generate and copy the
Template ID,Device Name, andAuth Token
- Upload the Code Below to ESP32:
#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_DEVICE_NAME "ESP32 DHT Monitor"
#define BLYNK_AUTH_TOKEN "YourAuthToken"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensorData() {
float h = dht.readHumidity();
float t = dht.readTemperature(); // Temperature in Celsius
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" ยฐC, Humidity: ");
Serial.print(h);
Serial.println(" %");
}
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dht.begin();
timer.setInterval(2000L, sendSensorData); // Read every 2 seconds
}
void loop() {
Blynk.run();
timer.run();
}
Be sure to replace:
YourTemplateIDYourDeviceNameYourAuthTokenYourWiFiSSIDandYourWiFiPassword
with actual values from your Blynk project and Wi-Fi credentials.
๐งช 6. Testing and Debugging Tips
- Open the Serial Monitor (set to 115200 baud) to verify the output.
- If the DHT sensor returns
NaN, double-check wiring and ensure the resistor is connected correctly. - Ensure the Blynk app is set up with the correct Virtual Pins (V0 for temperature, V1 for humidity).
- Confirm your ESP32 is in range of your Wi-Fi network and that the SSID/password are correct.
- If no data appears in the app, use
Serial.println()in multiple parts of the code to narrow down where it’s failing (Wi-Fi, sensor read, or Blynk update).
๐ 7. Project Extensions
Want to take this further? Here are some ideas:
- Add push notifications or email alerts if temperature exceeds a threshold.
- Log data to a cloud server or Google Sheets for historical trends.
- Use Node-RED for a customizable local dashboard.
- Add an OLED display to show live values locally on the device.
- Power it via a LiPo battery and use ESP32โs deep sleep mode to save power.
- Add a motion sensor to wake the ESP32 and only transmit when needed.