ESP32-Temp_Sensor
This ESP32 project is compiled by cyberCon31 for Smart Home System.
Using ESP32, DHT11 sensor, LCD Display I2C.
This ESP32 project lets you monitor Temperature & Humidity via Web Browser thru local WLAN and via Blynk.cloud
Sensor readings for Temperature & Humidity can be viewed from the LCD Display I2C connected directly to ESP32 development board.
Created 03-April-2026 --- Code can be found here:
https://app.cirkitdesigner.com/project/7e7a299f-c679-481d-aae5-a2616033e5e7
My project was composed of combined codes from the following sources:
- LAFVIN -- Project_9_ESP32_DHT11_Web_Server
https://www.dropbox.com/sh/osi3jtv5ncuyby2/AADkuo03wGXK8JiwwbV3zPc6a?dl=0
- Tech Trends Shameer -- Temperature and Humidity Monitor Using ESP32 and Blynk IOT - Blynk 2.0 Projects
https://www.youtube.com/watch?v=gjYcLOoiH6c&t=82s$0
- shameermohamed -- Create temperature-humidity-monitor-using-esp32.ino
https://www.youtube.com/watch?v=gjYcLOoiH6c&t=23s
- ESP32 I/O --ESP32 - DHT11 - LCD
https://esp32io.com/tutorials/esp32-dht11-lcd$0
Thank you and 73!
de cyb3rc0n31
Supplies
List of components:
- ESP32 Wifi IoT development board microcontroller
- ESP32 expansion board
- DHT11 sensor
- LCD Display 16x2 with I2C
Upload Code Using Arduino IDE
/*
This ESP32 code is compiled by cyberCon31 for Smart Home System.
Using ESP32, DHT11 sensor, LCD Display. This project can be locally viewed
from a web browser over Wifi, via Blynk.Cloud and via LCD display.
Created 03-April-2026
*/
#define BLYNK_TEMPLATE_ID "Your Blynk Template ID"
#define BLYNK_TEMPLATE_NAME "Your Blynk template name"
#define BLYNK_AUTH_TOKEN "Your Bkynk Authentication Token"
#define BLYNK_PRINT Serial
// Import required libraries
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include <Adafruit_Sensor.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Replace with your network credentials
char auth[] = BLYNK_AUTH_TOKEN;
const char* ssid = "Your Wireless LAN or Wifi SSID";
const char* password = "Your Wifi SSID password";
#define DHTPIN 4 // Digital pin connected to the DHT11 sensor
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows
DHT dht(DHTPIN, DHTTYPE);
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
String readDHTTemperature() {
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float t = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return "--";
}
else {
Serial.print("Temperature : ");
Serial.print(t);
return String(t);
}
}
String readDHTHumidity() {
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
if (isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
return "--";
}
else {
Serial.print(" Humidity : ");
Serial.println(h);
return String(h);
}
}
BlynkTimer timer;
void sendSensor() {
float t = dht.readTemperature();
float h = dht.readHumidity();
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, h);
}
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
</head>
<body>
<h2>ESP32 DHT Server</h2>
<h2>Smart-Home System by C.Cruz</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°C</sup>
</p>
<p>
<i class="fas fa-tint" style="color:#00add6;"></i>
<span class="dht-labels">Humidity</span>
<span id="humidity">%HUMIDITY%</span>
<sup class="units">%</sup>
</p>
</body>
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";
// Replaces placeholder with DHT values
String processor(const String& var){
//Serial.println(var);
if(var == "TEMPERATURE"){
return readDHTTemperature();
}
else if(var == "HUMIDITY"){
return readDHTHumidity();
}
return String();
}
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
dht.begin();
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
Blynk.begin(auth, ssid, password);
timer.setInterval(60000L, sendSensor); // set to send data every 1 minute.
//timer.setInterval(60000L, sendSensor); // 60,000ms = 1 minute
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTTemperature().c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", readDHTHumidity().c_str());
});
// Start server
server.begin();
}
void loop(){
Blynk.run();
timer.run();
float h = dht.readHumidity(); // read humidity
float t = dht.readTemperature(); // read temperature
lcd.clear();
// check whether the reading is successful or not
if (isnan(t) || isnan(h)) {
lcd.setCursor(0, 0);
lcd.print("Sensor Failed...");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(t);
lcd.write(223); // Degree symbol
lcd.print("C");
lcd.setCursor(0, 1); // display position
lcd.print("Humidity ");
lcd.print(h); // display the humidity
lcd.print(" %");
}
// wait a 2 seconds between readings
delay(5000);
}