How to Use ESP32 with LCD 1602 Display via I2C
How to Use ESP32 with LCD 1602 Display via I2C
This tutorial shows you how to connect an ESP32 board to a 1602 LCD display using the I2C interface. You’ll learn the wiring, library installation, and how to write code that displays text on the screen.
Required Components
- ESP32 NodeMCU board (ESP-WROOM-32)
- LCD 1602 with I2C Interface module
- Breadboard
- Male-to-female jumper wires
- Micro USB cable for computer connection
ESP32 to LCD 1602 Wiring
The I2C interface only needs 4 wires, which saves many GPIO pins on the ESP32.
| ESP32 | LCD 1602 I2C |
|---|---|
| VIN (5V) | VCC |
| GND | GND |
| D21 | SDA |
| D22 | SCL |
The VIN pin on ESP32 supplies 5V to power the LCD. If your ESP32 board doesn’t have a VIN pin, use the 5V pin instead.
Installing LiquidCrystal_I2C Library
- Download the library from https://github.com/marcoschwartz/LiquidCrystal_I2C
- Extract the files and move the LiquidCrystal_I2C folder to
Documents/Arduino/libraries/ - Close and reopen Arduino IDE
Example Code to Display Text on LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set LCD address - if screen doesn't work, try 0x3F instead of 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin();
lcd.backlight();
// Print on first row
lcd.setCursor(0, 0);
lcd.print("ESP32 + LCD 1602");
// Print on second row
lcd.setCursor(0, 1);
lcd.print("Hello World!");
}
void loop() {
// Nothing to do here
}
Adjustable points: If the display shows nothing, try changing the address from 0x27 to 0x3F because different LCD modules may use different I2C addresses.
How to Upload Code to ESP32
- Open the code in Arduino IDE and select Board as ESP32 Dev Module
- Choose the correct Port that matches your board
- Click the Upload button
- If a dialog asks to save the sketch, just click Cancel
When upload gets stuck: If the “Connecting…” message appears for more than 5 seconds, press and hold the BOOT button on the ESP32 board until the upload finishes.
Common LiquidCrystal_I2C Commands
| Command | Function |
|---|---|
lcd.begin(16, 2) | Initialize display 16 chars, 2 rows |
lcd.backlight() | Turn on LCD backlight |
lcd.noBacklight() | Turn off LCD backlight |
lcd.setCursor(col, row) | Set cursor position |
lcd.print("text") | Print text to display |
lcd.clear() | Clear the display |
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย