Home and IoTA Room Thermometer on an LCD
A DHT11 sensor measures the temperature and humidity, and a 16×2 display shows both, updating every two seconds.
Home and IoTAn ESP32 measures the room's temperature and humidity and serves a small web page you open in your phone's browser on the home Wi-Fi.
Written by the RoboHub team. A question? Write to us.
Choose a variation and the parts list updates.
Power the DHT22 from the 3V3 pin, connect its “−” to GND and its data pin to GPIO 4. You need a 10 kΩ resistor between data and power (modules often have one already).
Install the ESP32 boards package (esp32 by Espressif) and the “DHT sensor library” in the Arduino IDE.
Choose “ESP32 Dev Module” as the board. Put your network name and password in the code and upload it. On start the ESP32 prints its IP address to the Serial Monitor (115200). This code is for the ESP32: an Uno R4 WiFi needs a different Wi-Fi library (WiFiS3), with the sensor on 5V and a digital pin.
// ESP32 weather station: a DHT22 on GPIO 4 and a small web page
// that shows the temperature and humidity and refreshes itself every 10 seconds.
#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>
const char* WIFI_NAME = "your-network"; // your Wi-Fi network's name
const char* WIFI_PASSWORD = "your-password"; // and its password
const int DHT_PIN = 4; // the DHT22's data pin
DHT dht(DHT_PIN, DHT22);
WebServer server(80);
float temperature = NAN; // the last good reading, in °C
float humidity = NAN; // the last good reading, in %
unsigned long lastRead = 0;
// Keeps the old values when a reading fails (the DHT22 misses one now and then)
void readSensor() {
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t) && !isnan(h)) {
temperature = t;
humidity = h;
}
}
void handleRoot() {
String html = "<!DOCTYPE html><html><head><meta charset='utf-8'>";
html += "<meta name='viewport' content='width=device-width,initial-scale=1'>";
html += "<meta http-equiv='refresh' content='10'>"; // the phone reloads the page every 10 s
html += "<title>Weather station</title>";
html += "<style>body{font-family:sans-serif;text-align:center;margin-top:15vh}p{font-size:2.5em;margin:0.3em}</style>";
html += "</head><body>";
if (isnan(temperature)) {
html += "<p>No reading yet</p>";
} else {
html += "<p>";
html += String(temperature, 1);
html += " °C</p><p>";
html += String(humidity, 0);
html += " %</p>";
}
html += "</body></html>";
server.send(200, "text/html", html);
}
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Open this address on your phone: http://");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
readSensor();
}
void loop() {
server.handleClient();
if (millis() - lastRead >= 2000) { // the DHT22 needs 2 seconds between readings
lastRead = millis();
readSensor();
}
}Type that address into the browser of a phone on the same Wi-Fi. The readings refresh every 10 seconds.

Illustration, made with AI
Illustration: an ESP32 and a DHT22 sensor by a rainy window, and a phone in hand showing temperature and humidity gauges.
Step 4: Open it on your phone
Home and IoTA DHT11 sensor measures the temperature and humidity, and a 16×2 display shows both, updating every two seconds.
Home and IoTType the secret code and press #: with the right code the green light comes on and a servo slides the bolt open, with the wrong one the buzzer beeps three times.
SensorsAn ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.