Skip to content
DisplayLGPL-3.0v1.1.2

LiquidCrystal I2C

by Frank de Brabander

This library wraps the classic HD44780 character-LCD command set behind the same 4-pin I2C backpack used on both the LCD1602 and LCD2004. Once you call `lcd.init()`, writing text is just `setCursor(col, row)` followed by `print()` — the library handles the low-level I2C transactions to the PCF8574 expander for you. The exact same API works for any HD44780-compatible panel regardless of size — only the constructor's column/row arguments change between a 16x2 and a 20x4 display, which is why the LCD1602 and LCD2004 pages on this site share almost identical example code.

Installation

Arduino IDE — Library Manager

Sketch → Include Library → Manage Libraries → search LiquidCrystal I2C

PlatformIO

lib_deps = marcoschwartz/LiquidCrystal_I2C

Supported boards

Arduino UnoESP32STM32 Blue Pill

Examples

Print two lines of text

The baseline pattern behind every LCD1602/LCD2004 example on this site.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // address, cols, rows

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello, SolderHub");
}

void loop() {}

Clearing a line before rewriting it

print() does not clear leftover characters from a previous, longer value - pad with trailing spaces or call clear() first.

lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(value);
lcd.print("C   "); // trailing spaces erase leftover digits