ESP32 UNO - DHT11 - LCD

Want a desk gadget that tells you how warm and how damp your room is? Build an ESP32 Uno DHT11 LCD meter: the sensor measures the air, and a 16x2 LCD I2C screen shows both numbers without a computer. The ESP32 Uno form board refreshes the display every 2 seconds, so a warm hand or an open window shows up on the screen almost at once.

What you will do:

  1. Hook up a DHT11 temperature humidity module plus a 16x2 I2C screen on the ESP32 Uno
  2. Install two libraries from the Arduino IDE Library Manager: Adafruit DHT and DIYables_LCD_I2C
  3. Get °C and % values with readTemperature() and readHumidity()
  4. Print both lines on the LCD screen, with a real degree symbol
ESP32 Uno DHT11 LCD

Components You Need

1×ESP32 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×5V to 3.3V Level Converter (Optional, for SDA and SCL)
1×DHT11 Temperature Humidity Sensor Module
1×Alternatively, DHT11 Sensor
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Most LCD I2C displays available on the market are 5V displays. They may work with this board, but it is unsafe and can damage the board. We strongly recommend using the 3.3V LCD I2C display recommended above.

The Two Modules in Short

After this part, you know which job each module does in the build.

Module Job In This Project Bus or Signal Supply
DHT11 module Measures temperature and humidity One-wire style data on one pin 3.3V to 5V
LCD I2C 16x2 Shows two lines of 16 characters I2C (SDA and SCL) 5V

The DHT11 covers 0 to 50°C (about ±2°C) and 20 to 90% humidity (about ±5%). It gives a new reading about once per second, so the 2 second loop delay suits it well.

Need the full pinout, the basic sketch or the library details of each part? Go through these guides first:

ESP32 Uno Pinout

The labels printed on the headers (D2, SDA, SCL) are not the numbers you type in a sketch. Find D2 and the SDA/SCL pins on the picture below to see their GPIO numbers before you plug in any jumper.

ESP32 Uno pinout diagram

How to Connect

When you finish this step, the sensor data line sits on D2 and the screen sits on the I2C header.

The wiring diagram between ESP32 Uno DHT11 LCD

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

The wiring diagram may not show the correct wiring for the ESP32 Uno. The LCD backpack pulls SDA and SCL up to 5V, but ESP32 Uno pins are 3.3V only. The picture shows the LCD wired straight to SDA and SCL. We suggest a level converter between the LCD and the board, as the hardware list shows. We will update the diagram soon. Until then, follow the wiring table and the text on this page, not the picture.

Step 1 — DHT11 module

DHT11 Pin ESP32 Uno Pin
VCC (+) 3.3V
GND (-) GND
DATA (OUT) D2 (GPIO26)

Step 2 — LCD I2C display

LCD Pin ESP32 Uno Pin
VCC 5V
GND GND
SDA SDA (GPIO21)
SCL SCL (GPIO22)

Good to know: the DHT11 module has its own pull-up resistor on DATA. A bare 4-pin DHT11 needs an extra 10 kΩ resistor from DATA to 3.3V.

Good to know: A4 and A5 on this board are input-only analog pins, not I2C. The LCD must go to the separate SDA and SCL header pins.

WARNING

ESP32 Uno pins use 3.3V logic and are NOT 5V tolerant. Feed the DHT11 from 3.3V, so its DATA line never rises above 3.3V. The LCD backpack runs from 5V, and many backpacks pull SDA and SCL up to that 5V. For long-term use, put a bidirectional 3.3V/5V level shifter on the two I2C lines, or take off the pull-up resistors on the backpack so the lines idle at 3.3V.

ESP32 Uno Code

This sketch reads the DHT11 on GPIO26 every 2 seconds and writes temperature on line 1 and humidity on line 2 of the LCD.

/* * This ESP32 Uno code was developed by newbiely.com * * This ESP32 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-uno/esp32-uno-dht11-lcd */ #include <DIYables_LCD_I2C.h> #include <DHT.h> #define DHT11_PIN 26 // D2 (GPIO26) reads the DHT11 DATA line DIYables_LCD_I2C lcd(0x27, 16, 2); // DIYables LCD at I2C address 0x27, 16 characters x 2 lines DHT dht11(DHT11_PIN, DHT11); void setup() { dht11.begin(); // start talking to the DHT11 lcd.init(); // prepare the LCD (uses SDA GPIO21 / SCL GPIO22) lcd.backlight(); // switch the backlight on } void loop() { delay(2000); // the DHT11 needs a pause between two readings float humi = dht11.readHumidity(); // relative humidity in % float tempC = dht11.readTemperature(); // temperature in Celsius lcd.clear(); // NaN means the sensor did not answer if (isnan(humi) || isnan(tempC)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // move to line 1, column 0 lcd.print("Temp: "); lcd.print(tempC); // show the temperature value lcd.print((char)223); // code 223 draws the degree symbol lcd.print("C"); lcd.setCursor(0, 1); // move to line 2, column 0 lcd.print("Humi: "); lcd.print(humi); // show the humidity value lcd.print("%"); } }

※ NOTE THAT:

LCD I2C modules from different makers can use different addresses. This sketch uses 0x27, the address of the DIYables LCD. A blank screen with a lit backlight often means a different address, such as 0x3F.

Upload and Test

  1. First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
  2. Build the circuit by following the wiring table above.
  3. Plug in the USB Type-C cable between the ESP32 Uno and your computer.
  4. Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
  5. Open the Library Manager with the Libraries icon in the left bar of Arduino IDE.
  6. Get the sensor library: type "DHT", pick the DHT sensor library from Adafruit, then press Install.
  • Search for DHT sensor library created by Adafruit and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32 Dev Module
Library Manager
Type:
All
Topic:
All
DHT sensor library by Adafruit
Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors More info
1.4.6
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32 Dev Module on COM15
1
  1. Accept the extra libraries: the IDE lists some dependencies, so add them too with the Install All button.
  • Search for Adafruit Unified Sensor created by Adafruit and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32 Dev Module
Library Manager
Type:
All
Topic:
All
Adafruit Unified Sensor by Adafruit
A unified sensor abstraction layer used by many Adafruit sensor libraries. More info
1.1.14
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32 Dev Module on COM15
1
  1. Get the screen library: type "DIYables LCD I2C", pick DIYables_LCD_I2C by DIYables, then press Install.
  • Search for DIYables LCD I2C created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32 Dev Module
Library Manager
Type:
All
Topic:
All
DIYables LCD I2C by DIYables.io
This library is designed for HD44780-based I2C LCD displays. It provides LiquidCrystal-compatible API plus helper functions (text alignment, progress bars, predefined custom characters). Supports multiple I2C buses (Wire, Wire1, Wire2) for advanced boards like Arduino Giga, Due, and ESP32. Compatible with all Arduino-based platforms including Arduino Uno, Mega, Nano, ESP32, ESP8266, STM32, and Raspberry Pi Pico. More info
1.0.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32 Dev Module on COM15
1
  1. Paste the sketch into a new Arduino IDE window.
  2. Click Upload (Upload button) and wait for "Done uploading".
  3. Change the air around the sensor: breathe on it gently, or put it near a cup of warm tea.
  4. Read the screen: you should see lines like these, and the numbers move after a few seconds.
LCD Line Example Text
Line 1 Temp 26.00°C
Line 2 Humi 57.00%
Line 1 after breathing on it Temp 27.00°C
Line 2 after breathing on it Humi 71.00%
  1. Pro tip: humidity jumps faster than temperature when you breathe on the DHT11. Use that as a quick check that the sensor is alive before you trust the °C value.

Blank LCD? Go to the LCD I2C troubleshooting part.

Video Tutorial

See the ESP32 Uno build in action in the video below.

Code Explanation

By the end of this part, you can change any line of the sketch with confidence.

Code Part What It Does
#define DHT11_PIN 26 Sets D2 (GPIO26) as the DHT11 data pin
DIYables_LCD_I2C lcd(0x27, 16, 2) Creates the screen object with address 0x27 and a 16x2 size
dht11.begin() and lcd.init() Start the sensor and the screen once at power-up
readHumidity() and readTemperature() Return humidity in % and temperature in °C as float values
isnan(...) check Shows "Failed" when the sensor sends no valid data
lcd.print((char)223) Draws the ° sign from the LCD character set

The result is a screen that is cleared and redrawn every 2 seconds with fresh numbers.

ESP32 Uno vs UNO R4 for This Project

This table lists what is different when you move this build from the UNO R4 to the ESP32 Uno.

Item Arduino UNO R4 ESP32 Uno
Logic voltage 5V 3.3V
DHT11 data pin in code 2 (D2) 26 (D2 header pin)
LCD I2C pins SDA and SCL (also A4 and A5) SDA GPIO21 and SCL GPIO22 only
DHT11 supply 5V or 3.3V 3.3V recommended
Libraries DHT sensor library and DIYables_LCD_I2C Same libraries, no change
WiFi and Bluetooth WiFi on R4 WiFi only WiFi plus Bluetooth Classic and BLE
Arduino IDE board Arduino UNO R4 WiFi or Minima ESP32 Dev Module

The same wiring positions work as-is. Only the pin number in code changes, and you should watch the 5V pull-ups on the LCD I2C lines.

Go Wireless: Check the Room From Your Phone

After this part, you have an idea for reading the climate without walking to the LCD.

The ESP32 Uno has WiFi and Bluetooth built in. Keep the LCD for people in the room, and send the same two values to a phone or a browser too. A live chart also shows how humidity rises when you cook or take a shower.

Troubleshooting

Problem Possible Cause Solution
No COM port appears in Arduino IDE CH340 driver missing or a charge-only USB cable Install the CH340 driver and use a USB cable that carries data
Upload stops at "Failed to connect" or "Waiting for download" The board did not enter download mode Hold the BOOT button when the IDE starts uploading, then let go
Backlight lit but no characters I2C address is not 0x27, or contrast is too low Run an I2C scanner sketch, put the found address in the code, and turn the blue contrast screw
Screen completely dark LCD has no 5V, or its wires sit on A4 and A5 Give the LCD 5V and move SDA and SCL to GPIO21 and GPIO22
"Failed" on line 1 No valid data from the DHT11 Check DATA on D2 (GPIO26), the 3.3V and GND wires, and the pull-up on a bare sensor
Sketch will not compile, DHT.h not found Library not installed Install DHT sensor library and Adafruit Unified Sensor from the Library Manager
Random characters or a frozen screen Loose I2C jumper or long wires Push the SDA and SCL jumpers in firmly and keep them short
Temperature is a few degrees too high Heat from the board or the LCD reaches the sensor Move the DHT11 a few centimeters away from the board and the backpack

FAQ

How accurate is a DHT11 for a room display?

It is fine for a rough room reading. Expect about ±2°C on temperature and about ±5% on humidity. For better numbers, use a DHT22 with the same wiring idea.

Can the DHT11 run from the 5V pin of the ESP32 Uno?

It can run from 5V, but then the module pull-up lifts DATA to 5V. ESP32 Uno pins are not 5V tolerant, so 3.3V is the safe supply for this project.

Where do SDA and SCL connect on the ESP32 Uno?

Use the two pins marked SDA (GPIO21) and SCL (GPIO22) next to AREF. On this board A4 and A5 are input-only analog pins with no I2C function. Wire.begin() picks GPIO21 and GPIO22 by default, so no extra code is needed.

Do I need a level shifter between the LCD and the ESP32 Uno?

Often yes, because the backpack resistors tie the two I2C lines to its 5V supply. A cheap bidirectional level shifter keeps those lines at 3.3V on the board side. Removing the pull-up resistors on the backpack also works, because the I2C lines then idle at a safe level.

How do I display Fahrenheit instead of Celsius?

Call dht11.readTemperature(true), which returns °F. Then print "F" in place of "C" on line 1.

Which other pins can read the DHT11 on the ESP32 Uno?

Most digital header pins work, for example D3 (GPIO25) or D7 (GPIO14). Write the GPIO number in DHT11_PIN, not the D label. Skip A2 to A5 if you need the internal pull-up, and avoid D8 (GPIO12), D10 (GPIO5) and A0 (GPIO2), which are boot strapping pins.

Is the ESP32 Uno code different from the UNO R4 code here?

Only one line changes. The UNO R4 uses pin 2 for DHT11 DATA, while the ESP32 Uno uses 26, which is the same D2 header position. Both libraries work on both boards.

Why does Arduino IDE ask me to install a CH340 driver?

The ESP32 Uno uses a CH340 USB-to-serial chip for upload and Serial Monitor. Windows and macOS may need its driver before the COM port appears.

Can I fit a second DHT11 or a DHT22 in this build?

Yes. Give the second sensor its own data pin and create a second DHT object with its pin and type. Then show its values on the same LCD, or switch between the two sensors every few seconds.

What if this climate display needs more pins than the Uno headers give?

The ESP32 Uno has a few extra holes near the power header. GPIO32 and GPIO33 offer I/O, PWM and analog on ADC1, so they still read analog values while WiFi is on. GPIO15 offers I/O, PWM and analog on ADC2. Solder pin headers there and write the GPIO number in code. GPIO32 or GPIO33 are a good spot for a second DHT11 or a button. Two warnings: GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC spot) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code, so pick GPIO32/33 first. Never use the six holes under the digital header (SD0 to SD3, CMD, CLK = GPIO6 to GPIO11), because they connect to the flash chip and using them crashes the board.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!