Skip to content

LCD · ESP32 guide

Interfacing 16x2 Character LCD with I2C Backpack with ESP32

The classic 16x2 text display made simple with I2C — just 4 wires and you're up and running.

Updated November 25, 2026 Arduino C++LiquidCrystal I2CAlso forArduino Uno

What is the LCD1602 I2C?

The LCD1602 I2C is a 16×2 character display with a PCF8574 I2C backpack. It shows 16 characters on each of two rows, uses the classic HD44780 controller, and needs only four wires — VCC, GND, SDA and SCL — instead of the dozen connections a bare LCD requires.

That makes it one of the most popular first displays for Arduino, ESP32, Raspberry Pi and STM32 projects: sensor readouts, menus, counters, timers and status messages all fit comfortably, and the same library scales up to the 20×4 version. It is text-only (plus up to eight custom characters), so for icons, graphs or arbitrary pixels use a graphic display such as the SSD1306 OLED instead.

How the LCD1602 I2C works

Inside the display, the HD44780 controller expects commands and character data over a parallel bus: register select (RS), read/write (RW), enable (E) and four data lines (D4–D7) when run in 4-bit mode. The PCF8574 on the backpack is an I2C I/O expander wired to those lines, plus a transistor that switches the backlight.

When your sketch calls lcd.print(), the library splits each byte into two 4-bit halves, writes them to the PCF8574 over I2C and pulses the enable line so the HD44780 latches them. You never touch the parallel bus yourself, but it explains why the display is slower than a graphic one and why you should update only the characters that change instead of clearing the whole screen every loop.

The controller keeps the text in its own display memory, so characters stay on screen without any refreshing from your code.

I2C address: 0x27 or 0x3F?

The address depends on which chip is on the backpack. A PCF8574 defaults to 0x27, while a PCF8574A defaults to 0x3F. Both can be changed with the three solder pads labelled A0, A1 and A2: bridging a pad pulls that address bit low, giving 0x20–0x27 for the PCF8574 and 0x38–0x3F for the PCF8574A. That lets you run several displays on the same I2C bus.

If you are not sure which chip you have, upload the scanner below and use the address it prints in your sketch.

Contrast and backlight

The blue trimmer on the back of the backpack sets the contrast. If you see a row of solid blocks, or a lit backlight with no text at all, turn the trimmer slowly with a small screwdriver until the characters appear. This is the most common reason an LCD1602 "doesn't work" and has nothing to do with your code.

The backlight is switched with lcd.backlight() and lcd.noBacklight(). On most backpacks a small jumper next to the header disconnects the backlight entirely if you want to save power.

Custom characters

Each character cell is a 5×8 pixel grid, and the controller lets you define up to eight of your own (slots 0–7) — hearts, degree symbols, battery icons or progress-bar segments. Define them once in setup(), then draw them with lcd.write(byte(slot)).

What you can build

  • Sensor dashboards: show temperature, humidity, pressure or distance readings from DHT22, BME280 or HC-SR04 sensors.
  • Menus and settings screens: pair the display with push buttons or a rotary encoder.
  • Clocks, timers and counters: combine with an RTC module or millis() for a stopwatch or countdown.
  • Status panels: show Wi-Fi state, IP address or error codes on an ESP32 or Raspberry Pi project.
  • Scrolling messages: use lcd.scrollDisplayLeft() to show text longer than 16 characters.

Wiring and usage best practices

  1. Find the address first. Run the I2C scanner instead of assuming 0x27.
  2. Power from 5 V and share ground. The display is dim or blank on 3.3 V, and SDA/SCL need a common ground with the microcontroller.
  3. Match the constructor to your display. LiquidCrystal_I2C lcd(0x27, 16, 2); for the LCD1602, (0x27, 20, 4) for the LCD2004.
  4. Don't clear the screen every loop. lcd.clear() is slow and makes the text flicker. Overwrite the characters that change and pad with spaces to erase old ones.
  5. Keep I2C wires short and make sure the header is soldered or seated firmly; loose jumpers cause garbled characters.
  6. Power down before rewiring so a mis-plugged VCC or GND line cannot damage the backpack.

Frequently asked questions

Do I need a library? Yes. Use LiquidCrystal I2C on Arduino-compatible boards (Arduino IDE → Library Manager). On Raspberry Pi use RPLCD. The board-specific sections below show the exact install steps.

Can I run it at 3.3 V? Some modules work, but contrast and brightness are usually poor. A 5 V supply is the reliable choice; use a level shifter if your microcontroller's I2C pins are 3.3 V only.

Can I connect more than one LCD1602 to the same I2C bus? Yes, as long as each backpack has a different address. Bridge the A0–A2 solder pads on the backpacks to change their addresses.

What is the difference between the LCD1602 and the LCD2004? Same library, wiring and I2C backpack — the LCD2004 simply has 20 columns and 4 rows. Pass (0x27, 20, 4) to the constructor.

Can it display Hindi, Unicode or images? Not directly. The controller has a fixed character ROM, and you can define at most eight custom 5×8 glyphs. For other scripts or graphics, use an OLED or TFT display.

Why is the text stuck on the first line? Call lcd.setCursor(0, 1) to move to the second row; the cursor does not wrap automatically.

Build a clock: a DS3231 RTC shares the same I2C bus (address 0x68) and keeps time to about a minute a year, even when the board is unplugged.

Specifications

Display
16 characters × 2 lines, each character a 5×8-dot cell
Controller
HD44780-compatible, driven in 4-bit mode by the backpack
I2C backpack
PCF8574 or PCF8574A 8-bit I/O expander
Supply voltage
5 V DC. The PCF8574 itself accepts 2.5 to 6 V, but most displays are faint or blank on 3.3 V
Supply current
About 25 mA with the backlight on; less with it off. Varies by module
I2C address
0x20 to 0x27 (PCF8574) or 0x38 to 0x3F (PCF8574A); 0x27 and 0x3F are the usual defaults
Address selection
Solder pads A0, A1 and A2 on the backpack
I2C speed
Up to 100 kHz (standard mode)
Backlight
On or off by jumper or software (PCF8574 pin P3); not dimmable without modification
Contrast
Set with the 10 kΩ blue trimmer on the backpack
Custom characters
Up to 8 user-defined 5×8 glyphs
Character set
Built-in ROM, either A00 (Japanese katakana) or A02 (European), depending on the module
Line addresses
Line 1 starts at DDRAM address 0x00, line 2 at 0x40

Pinout

PinNameDescription
1GNDGround; connect to the microcontroller ground
2VCCPower, 5 V DC
3SDAI2C data (Arduino Uno A4, Mega 20, ESP32 GPIO21)
4SCLI2C clock (Arduino Uno A5, Mega 21, ESP32 GPIO22)

Wiring & code

Setting up LCD1602 I2C with ESP32

Library

LiquidCrystal I2C by Frank de Brabander

Arduino IDE → Tools → Manage Libraries → search "LiquidCrystal I2C" by Frank de Brabander → Install

Library guide

Wiring

Component pinESP32 pinNote
VCC5V (VIN)Most backpacks need a real 5V rail for full contrast/brightness - power from VIN/5V, not 3V3.
GNDGND
SDAGPIO21Default I2C data pin. Through a level shifter (LV1 to GPIO21, HV1 to SDA): the backpack pulls SDA up to 5 V.
SCLGPIO22Default I2C clock pin. Through the level shifter (LV2 to GPIO22, HV2 to SCL).
LCD1602 I2C on an ESP32 in the SolderHub Simulator: the LCD runs from 5V, and SDA/SCL pass through a 4-channel level shifter (HV to 5V, LV to 3V3) to GPIO21 and GPIO22, so the backpack's 5 V pull-ups never reach the ESP32
sketch.ino
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Wire.begin();  // defaults to GPIO21 (SDA) / GPIO22 (SCL) on most ESP32 boards
  lcd.init();
  lcd.backlight();

  lcd.setCursor(0, 0);
  lcd.print("Hello, SolderHub");
  lcd.setCursor(0, 1);
  lcd.print("16x2 I2C LCD");
}

void loop() {
  static unsigned long lastUpdate = 0;
  static int counter = 0;

  if (millis() - lastUpdate > 1000) {
    lastUpdate = millis();
    lcd.setCursor(0, 1);
    lcd.print("Uptime: ");
    lcd.print(counter++);
    lcd.print("s   ");
  }
}
  • The backpack's I2C pull-ups are tied to VCC, so with the LCD on 5V the SDA and SCL lines idle at 5 V. ESP32 GPIOs are not 5 V tolerant (Espressif's datasheet limits inputs to VDD + 0.3 V), so put a level shifter between them, as in the diagram above: LV side to 3V3 and GPIO21/22, HV side to 5V and the LCD. Powering the LCD from 3V3 instead avoids the shifter, but most 5 V panels then show very faint text.
  • If your board wires I2C to non-default pins, call Wire.begin(SDA_PIN, SCL_PIN) before lcd.init().

Keep learning

Related guides & projects