ESP32 S3 UNO - DHT22 - LCD

This ESP32 S3 Uno DHT22 LCD tutorial shows you how to build a small weather display. The ESP32 S3 Uno form board reads temperature and humidity from a DHT22 sensor module and prints both values on a 16x2 LCD I2C display. The screen updates every 2 seconds, so you can watch the numbers change when the air gets warmer or more humid.

In this tutorial, you will:

  1. Wire a DHT22 module and an LCD I2C display to the ESP32 S3 Uno
  2. Install the DHT sensor library and the DIYables LCD I2C library in Arduino IDE
  3. Read temperature and humidity with Arduino code
  4. Show the DHT22 readings on the LCD I2C screen
ESP32 S3 Uno DHT22 LCD

Hardware Preparation

1×ESP32 S3 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×DHT22 Temperature Humidity Sensor Module
1×Alternatively, DHT22 Sensor
1×Jumper Wires
1×5V to 3.3V Level Converter (Optional, for SDA and SCL)

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.

Overview of DHT22 and LCD

This project puts together two parts that each have their own tutorial. If one of them is new to you, read its tutorial first. There you learn the pinout, how the part works, and the basic code.

  1. ESP32 S3 Uno - DHT22 Sensor tutorial covers the DHT22 pinout, the pull-up resistor and how to read temperature and humidity.
  2. ESP32 S3 Uno - LCD I2C tutorial covers the 16x2 LCD, its I2C address and how to print text.

The DHT22 sends its data as digital pulses on one wire, so the ESP32 S3 Uno does not use its ADC here. The LCD needs only the two I2C lines, SDA and SCL.

ESP32 S3 Uno Pinout

The image below shows the pinout of the ESP32 S3 Uno form board. Use it to find the D2, SDA and SCL header pins and their GPIO numbers before you wire the circuit.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The DHT22 data pin goes to D2, and the LCD goes to the SDA and SCL header pins. Follow the diagram and the table below.

The wiring diagram between ESP32 S3 Uno DHT22 LCD

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 S3 Uno Pin
DHT22 VCC (+) 3.3V
DHT22 GND (-) GND
DHT22 DATA (OUT) D2 (GPIO18)
LCD VCC 5V
LCD GND GND
LCD SDA SDA (GPIO8)
LCD SCL SCL (GPIO9)

WARNING

The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. Power the DHT22 module from 3.3V, so its pull-up resistor keeps the DATA line at 3.3V. Many LCD I2C backpacks pull SDA and SCL up to their own 5V supply. To keep the board safe, pass SDA and SCL through a bidirectional 5V to 3.3V level converter, or remove the pull-up resistors on the LCD backpack.

※ NOTE THAT:

On the ESP32 S3 Uno, A4 and A5 are NOT I2C pins. Always wire the LCD to the SDA and SCL header pins.

ESP32 S3 Uno Code - DHT22 Sensor - LCD I2C

The sketch waits 2 seconds, then reads humidity and temperature in Celsius from the DHT22. It prints the temperature on the first LCD row and the humidity on the second row. If the sensor gives no valid data, the LCD shows "Failed" instead. The DHT22 data pin is set to GPIO18, which is the D2 header pin.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-dht22-lcd */ #include <DIYables_LCD_I2C.h> #include <DHT.h> #define DHT22_PIN 18 // The ESP32 S3 Uno pin D2 (GPIO18) connected to DHT22 module DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows DHT dht22(DHT22_PIN, DHT22); void setup() { dht22.begin(); // initialize the sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { delay(2000); // wait a few seconds between measurements float humi = dht22.readHumidity(); // read humidity float tempC = dht22.readTemperature(); // read temperature lcd.clear(); // check if any reads failed if (isnan(humi) || isnan(tempC)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // start to print at the first row lcd.print("Temp: "); lcd.print(tempC); // print the temperature lcd.print((char)223); // print ° character lcd.print("C"); lcd.setCursor(0, 1); // start to print at the second row lcd.print("Humi: "); lcd.print(humi); // print the humidity lcd.print("%"); } }

※ NOTE THAT:

The I2C address of an LCD can be different from one maker to another. The code uses 0x27, which is the address of the DIYables LCD. If your screen stays empty, scan for the address and change it in the code.

Detailed Instructions

Do these steps in order:

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Open the Library Manager by clicking the Libraries icon on the left side of Arduino IDE.
  6. Install the DHT library: search for DHT, find the DHT sensor library by Adafruit and click 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
ESP32S3 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
ESP32S3 Dev Module on COM15
1
  1. Install the dependencies: Arduino IDE asks to install more libraries. Click Install All.
  2. Install the LCD library: search for DIYables LCD I2C, find the DIYables_LCD_I2C library by DIYables and click 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
ESP32S3 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
ESP32S3 Dev Module on COM15
1
  1. Copy the code above and paste it into Arduino IDE.
  2. Upload the code by clicking the Upload button.
  3. Test it: breathe on the sensor, or hold it in your hand to make it warmer.
  4. Look at the LCD: the first row shows the temperature in °C and the second row shows the humidity in %. The values change after a few seconds.
  5. Tip: if the LCD shows "Failed", the board cannot read the sensor. Check the DATA wire on D2 (GPIO18) and the power wires of the DHT22.

If the LCD shows nothing, read the Troubleshooting for LCD I2C.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Can I power the DHT22 from 3.3V on the ESP32 S3 Uno?

Yes. The DHT22 works from 3.3V to 5V, so 3.3V is fine. It is also the safe choice, because the pull-up resistor then keeps the DATA line at 3.3V, which the ESP32 S3 Uno pins can handle. A 5V supply would put 5V on GPIO18.

Why is the LCD wired to SDA and SCL and not to A4 and A5?

On the UNO R4, A4 and A5 are the I2C pins. On the ESP32 S3 Uno they are only analog pins. I2C is on the separate SDA (GPIO8) and SCL (GPIO9) header pins, and Wire.begin() uses them by default.

Why does the LCD show "Failed"?

The DHT library could not get valid data from the sensor. Most of the time the DATA wire is loose or on the wrong pin, or the sensor has no power. Reading faster than once every 2 seconds can also cause failed reads, so keep the delay(2000) in the loop.

Can I use another pin for the DHT22?

Yes. Any normal I/O pin works. Change DHT22_PIN to the GPIO number, not the D label. For example, D7 is 14. Avoid D6 (GPIO3) and D9 (GPIO46), because they are boot strapping pins.

How do I show the temperature in Fahrenheit?

Call dht22.readTemperature(true) instead of dht22.readTemperature(). Then change the "C" after the degree sign to "F" in the code.

What if my project needs more pins than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 support I/O, PWM and analog. GPIO45 and GPIO35 to GPIO42 support I/O and PWM. GPIO47 and GPIO48 are output only, with PWM. Solder pin headers to use them and write the GPIO number in code. For a second DHT22, use GPIO15, GPIO16 or GPIO35 to GPIO42. The DATA line is both input and output, so GPIO47/GPIO48 will not work. Be careful with two things. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port in Arduino IDE USB driver is missing or the board is not in upload mode Install the CP210x or CH340 driver, or hold BOOT while pressing RESET
LCD shows nothing at all LCD not powered, or SDA/SCL wired to A4/A5 Power the LCD from 5V and wire SDA and SCL to the SDA (GPIO8) and SCL (GPIO9) header pins
LCD backlight is on but there is no text Wrong I2C address or low contrast Run an I2C scanner, set the right address in the code, and turn the contrast screw on the backpack
LCD shows Failed The board cannot read the DHT22 Check the DATA wire on D2 (GPIO18) and the VCC and GND wires
Compile error about DHT.h or DIYables_LCD_I2C.h A library is not installed Install the DHT sensor library, Adafruit Unified Sensor and DIYables_LCD_I2C from the Library Manager
Readings fail now and then Sensor is read too often Keep at least 2 seconds between readings
Temperature reads too high Sensor is close to the board or the LCD backlight Move the DHT22 away from warm parts with longer wires

※ 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!