Introduction
In this tutorial, we will interface a 16×2 LCD with I2C module and DHT11 sensor with ESP32.
The ESP32 will read temperature and humidity values from DHT11 sensor and display them on LCD.
Required Components
| Component | Quantity |
|---|---|
| ESP32 Board | 1 |
| 16×2 LCD with I2C Module | 1 |
| DHT11 Sensor | 1 |
| Breadboard | 1 |
| Jumper Wires | Few |
DHT11 Sensor
DHT11 is a temperature and humidity sensor.
- Measures temperature in °C
- Measures humidity in %
- Simple digital output
LCD I2C Module
I2C module reduces LCD wiring using only 2 communication pins.
| LCD I2C Pin | ESP32 Connection |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | GPIO 21 |
| SCL | GPIO 22 |
DHT11 Connection
| DHT11 Pin | ESP32 Connection |
|---|---|
| VCC | 3.3V |
| GND | GND |
| DATA | GPIO 4 |

Install Required Libraries
Install the following libraries from Arduino IDE Library Manager:
- DHT Sensor Library
- LiquidCrystal I2C
- Adafruit Unified Sensor
Open:
Sketch > Include Library > Manage Libraries
ESP32 LCD + DHT11 Program
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
dht.begin();
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print(" %");
delay(2000);
}
Program Explanation
| Code | Purpose |
|---|---|
| dht.readTemperature() | Reads temperature value |
| dht.readHumidity() | Reads humidity value |
| lcd.setCursor() | Sets LCD cursor position |
| lcd.print() | Displays text on LCD |
Output
After uploading the code:
- LCD displays temperature value
- LCD displays humidity value
- Values update automatically every 2 seconds
Important Notes
- Common LCD I2C address is
0x27. - If LCD does not work, try address
0x3F. - DHT11 is slower compared to DHT22.
- Use proper USB cable for stable ESP32 operation.
Buy On Amazon
