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

Libraries / Displays
Arduino library · Displays

# LiquidCrystal: a 16x2 LCD on six Arduino pins

LiquidCrystal ships with the Arduino IDE and drives an HD44780 character LCD connected directly to digital pins, with no backpack. In the usual 4-bit wiring you need six signals: RS (register select), E (enable) and the data lines D4 to D7. RW goes to ground because the sketch only ever writes, and D0 to D3 stay unconnected.

Open the example in the editor See the calls

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

## What LiquidCrystal does

Two more connections are not signals at all, and they are where most first attempts go wrong. V0, the contrast pin, goes to the wiper of a 10 kΩ potentiometer between 5 V and ground; and pins 15 and 16 (A and K) power the backlight, usually through a 220 Ω resistor. Without the pot you will often see nothing even with perfect code.

This is the starter-kit way to wire an LCD, and it costs a lot of pins. If you are short of them, the same display on an I2C backpack needs only SDA and SCL and uses the LiquidCrystal_I2C library with almost the same calls.

Library Manager name | LiquidCrystal

Author | Arduino, Adafruit

Include | #include <LiquidCrystal.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, 16x2, Character LCD, 20x4

## Install it

It builds on every board Mokxi compiles for.

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

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

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 lcd(12, 11, 5, 4, 3, 2)

Names the pins in the order RS, E, D4, D5, D6, D7. The library also accepts eight data pins, and an RW pin, if you wire them.

### lcd.begin(16, 2)

Tells the library the size of the display and sends the set-up sequence. A 20x4 module is lcd.begin(20, 4).

### lcd.print(millis() / 1000)

Writes text or a number at the cursor, the same way Serial.print() formats it.

### lcd.setCursor(col, row)

Moves the cursor. Row 0 is the top line; on a 16x2, column 15 is the last character of a row.

### lcd.createChar(1, smiley)

Defines a custom character from eight bytes, one a row, five bits wide. Call setCursor() again afterward, since defining a character moves the controller’s address.

### lcd.blink()

Shows a blinking block at the cursor; cursor() shows an underline instead. noBlink() and noCursor() hide them.

### lcd.noDisplay()

Hides the text without erasing it, and display() shows it again: an easy way to flash a message.

## Example: Hello, world on a 16x2 LCD

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

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 12 to Character LCD, 16x2 RS
- Arduino Uno R3 11 to Character LCD, 16x2 E
- Arduino Uno R3 5 to Character LCD, 16x2 D4
- Arduino Uno R3 4 to Character LCD, 16x2 D5
- Arduino Uno R3 3 to Character LCD, 16x2 D6
- Arduino Uno R3 2 to Character LCD, 16x2 D7
- Arduino Uno R3 GND to Character LCD, 16x2 RW
- Arduino Uno R3 GND to Character LCD, 16x2 V0
- Arduino Uno R3 5V to Character LCD, 16x2 VDD
- Arduino Uno R3 GND to Character LCD, 16x2 VSS
- Arduino Uno R3 5V to Character LCD, 16x2 A
- Arduino Uno R3 GND to Character LCD, 16x2 K

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### The top row is solid blocks and the bottom row is empty

That is a powered display that has not been initialized, or contrast set too high. Check the V0 potentiometer, then check that RS and E are on the pins the constructor names and that begin() runs.

### Random symbols instead of the text

One of D4 to D7 is loose or the constructor lists them in the wrong order. The order is RS, E, D4, D5, D6, D7; compare each wire against that list.

### Text is there but only visible at an angle

Contrast is off. Wire V0 to a 10 kΩ pot between 5 V and GND and turn it, or as a fixed choice tie V0 to ground through a resistor of about 1 to 2 kΩ.

## Projects that use LiquidCrystal

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

LCD1602 on pins 7 to 12 A 16x2 LCD with RS on pin 7, E on 8 and D4 to D7 on pins 9 to 12: a greeting on the top line and the seconds since reset under it. LCD1602 hello A 16x2 character LCD on six pins with the LiquidCrystal library: a greeting on the top line and the seconds since reset under it. Ultrasonic distance on an LCD (TRIG 2, ECHO 3) An HC-SR04 with TRIG on pin 2 and ECHO on pin 3 measures the distance in front of it, shown on a 16x2 LCD wired to pins 4, 6 and 10 to 13. Answer ball Ask a question and tip the tilt switch: the 16x2 LCD shows one of eight answers, picked with random(). Thermistor thermometer A 10k thermistor and a 10k resistor make a divider on A0, and the beta equation turns the reading into degrees on a 16x2 LCD. Ultrasonic ranging on an LCD Hold the button on A0 and an HC-SR04 (TRIG on pin 9, ECHO on 3) measures the distance in front of it, shown on a 16x2 LCD wired to pins 2, A3, 8, 7, A2 and 4.

## Keep going

### Learn

- Arduino LCD 16x2 Without I2C: Wiring and Code
- Arduino LCD 20x4: I2C Example Code and Library

### Parts

- Character LCD, 16x2
- Character LCD, 20x4

### More displays libraries

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

Every built-in library · Open the editor

## Try LiquidCrystal without installing anything

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

Start building free

Open the editor
