Source: https://mokxi.com/libraries/liquidcrystal-i2c
Updated: 2026-11-02

Libraries / Displays
Arduino library · Displays

# LiquidCrystal I2C: a 16x2 LCD on four wires

Most 16x2 and 20x4 character LCDs sold for Arduino come with a small board soldered on the back: a PCF8574 I/O expander that turns the display’s sixteen pins into four (GND, VCC, SDA and SCL). LiquidCrystal_I2C, the Frank de Brabander library in the Library Manager, speaks to that expander and gives you the same print(), setCursor() and clear() calls as the plain LiquidCrystal library.

Open the example in the editor See the calls

Built in on Mokxi: #include <LiquidCrystal_I2C.h> and it builds, with nothing to install. Free, and no account needed.

## What LiquidCrystal I2C does

The constructor takes the backpack’s I2C address and the size of the display. Boards built on the PCF8574T answer at 0x27 and those built on the PCF8574AT at 0x3F; the three solder pads A0 to A2 move it within that range. When you are not sure, run an I2C scanner once and use what it prints.

The blue potentiometer on the backpack sets the contrast. A brand new module often shows nothing, or a row of solid blocks, until that pot is turned, which is the first thing to try before suspecting the code.

Library Manager name | LiquidCrystal I2C

Author | Frank de Brabander

Include | #include <LiquidCrystal_I2C.h>

Boards | every board Mokxi compiles for

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Character LCD with I2C backpack, Character LCD, 20x4, with I2C backpack

## Install it

It builds on every board Mokxi compiles for.

In Mokxi it is built in: #include <LiquidCrystal_I2C.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "LiquidCrystal I2C" by Frank de Brabander from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add LiquidCrystal I2C to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.2, so a sketch written here builds there too.

What to know in the simulator: F Malpartida’s NewLiquidCrystal forms build too (LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE) and begin(16, 2)); the pin map named is the usual backpack’s, which every Mokxi module is.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · ATtiny85 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### LiquidCrystal_I2C lcd(0x27, 16, 2)

Creates the display at I2C address 0x27 with 16 columns and 2 rows. A 20x4 module is LiquidCrystal_I2C lcd(0x27, 20, 4).

### lcd.init()

Starts I2C and sends the controller its set-up. Some forks call it begin(); call it once in setup().

### lcd.backlight()

Turns the backlight on through the backpack. Without it the text is there but very hard to see; noBacklight() turns it off again.

### lcd.setCursor(0, 1)

Moves to column 0 of row 1, the second line. Columns and rows count from zero.

### lcd.clear()

Blanks the screen and returns the cursor to 0, 0. It takes about 2 ms, so calling it every loop makes the text flicker; overwrite with spaces instead.

### lcd.createChar(0, heart)

Stores a custom 5 by 8 character in one of eight slots (0 to 7). Print it with lcd.write(0).

### lcd.scrollDisplayLeft()

Shifts everything on the display one column left, for scrolling text longer than the screen. Call it in a loop with a short delay between steps.

## Example: enjoyneering’s LiquidCrystal_I2C: the backpack named pin by pin

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 A4 to Character LCD with I2C backpack SDA
- Arduino Uno R3 A5 to Character LCD with I2C backpack SCL
- Arduino Uno R3 5V to Character LCD with I2C backpack VCC
- Arduino Uno R3 GND to Character LCD with I2C backpack GND

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The backlight is on but the screen shows a row of solid blocks

Either the contrast pot needs turning or init() never reached the display. Turn the pot slowly first; if the blocks stay, check the address with an I2C scanner and that SDA and SCL go to the board’s I2C pins.

### Nothing at all: no text and no blocks

The address in the constructor is wrong (0x27 against 0x3F is the usual mix-up) or the module has no power. Run an I2C scanner and put the address it finds in the constructor.

### Only the first letter of each print() appears

An old copy of the library written before Arduino 1.0 is installed. Remove it from the libraries folder and install LiquidCrystal I2C from the Library Manager, which returns the byte count print() expects.

### 'LiquidCrystal_I2C' does not name a type

The header was not found or a different library with the same file name won. Check the #include line spelling, then make sure only one LiquidCrystal_I2C library is installed.

## Projects that use LiquidCrystal I2C

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

I2C LCD1602: find its address, then say hello A 16x2 LCD with an I2C backpack on A4 and A5. Reversing radar: ultrasonic, buzzer and I2C LCD An HC-SR04 (TRIG 8, ECHO 7) measures the gap behind the car; an active buzzer on pin 9 beeps faster as it closes, and an I2C LCD on A4 and A5 shows the distance. UV index meter A GUVA-S12SD UV sensor and a 16x2 I2C LCD: the UV index and how risky it is, from low to extreme. Water pressure gauge A 0.5 to 4.5 V stainless pressure transducer on a water line and a 16x2 I2C LCD: the pressure in psi and bar, with a warning when it drops. Water meter A YF-S201 flow sensor’s pulses counted on an interrupt: 450 make a liter, and an I2C LCD shows the flow and the liters so far. DC voltmeter A 0 to 25 V voltage sensor module across a bench supply, and the voltage on a 16x2 I2C LCD: two resistors make it a fifth, and the sketch multiplies by five.

## Keep going

### Learn

- Arduino LCD I2C 16x2: Wiring, Code, Scrolling Text
- Arduino I2C LCD Not Working: Blank, Blocks, No Text
- I2C Scanner for Arduino and ESP32, and Fixes

### Parts

- Character LCD with I2C backpack
- Character LCD, 20x4, with I2C backpack

### More displays libraries

- Adafruit SSD1306
- Adafruit GFX Library
- LiquidCrystal
- LCD_I2C
- hd44780
- TFT_eSPI
- U8g2
- U8glib

Every built-in library · Open the editor

## Try LiquidCrystal I2C without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
