Wiring DHT11 and DHT22 to ESP32 and Displaying Values on a Web Server

Engineering illustration: Wiring DHT11 and DHT22 to ESP32 and Displaying Values on a Web Server

This project combines a DHT11 or DHT22 sensor with an ESP32 board to display temperature and humidity directly on a web page that can be opened from any device on the same network, with no separate app needed.

Components needed

An ESP32 board, a DHT11 or DHT22 sensor, a 10k-ohm pull-up resistor (unnecessary if the module already includes one), and connecting wires.

Wiring it up

The sensor connects with three pins: power (VCC) to a 3.3V pin on the ESP32, ground (GND), and the data line to GPIO4. The 10k-ohm pull-up resistor between the data line and the power pin keeps the signal stable, and it's usually built into ready-made sensor breakout boards.

How it works

The ESP32 operates in Station (STA) mode, connecting to the home WiFi network using credentials stored in the code, and the WebServer library creates an HTTP server listening on port 80. When a browser accesses the board's IP address, the board reads the current values from the sensor via the DHT library and generates an HTML page showing temperature in Celsius and relative humidity as a percentage. The code usually adds an automatic meta-refresh tag every two seconds, so the values on the page update automatically without a manual reload.

You can find ESP32 boards and DHT11/DHT22 sensors at Juthour Tech.

اترك تعليقا

*
*
يمكن للأعضاء المسجلين فقط ترك تعليقات.