Liquid Crystal Example


The LiquidCrystal library allows you to control an LCD displays that is compatible with the Hitachi HD44780 driver.

This sketch example prints "Hello,!" to the LCD and shows the time in seconds since the Arduino has started (or has been reset).

The LCD uses a microcontroller to control the display. 
The communicating interface between Arduino and the LCD is made by the following PINs:

  • Register Select (RS): this PIN controls the LCD's memory where you are writing. You can write on the data register (which contains what goes on the screen) or on the instruction register (which is where the LCD's controller looks for instructions on what to do next)
  • Read/Write (R/W): this PIN selects reading mode or writing mode
  • Enable: this PIN enables writing to the LCD's registers
  • 8 Data PINs(D0 -D7): the states of these PINs (high or low) are the bits that you're writing to a register when you write, or the values you're reading when you read.
  • Constrast PIN (Vo): this PIN is used to control the display contrast
  • +5V and Gnd PINs: these are used to power up the LCD
  • LED Backlight PINs (Bklt+ and BKlt-): used to turn on and off the LED backlight

Controlling the display implies to write what you want to display into the data and instruction registers. 
The LiquidCrystal library allows you to control the display without using low level instructions.

Hitachi-compatible LCDs can be controlled in 4-bit or 8-bit mode. The 4-bit mode requires 7 PINs while the 8-PIN mode requires 11 PINs. The example shown in this guide shows how to control a 2x16 LCD using 4-bit mode.

Hardware Required

  • Arduino Board
  • LCD Screen (compatible with Hitachi HD44780 driver)
  • 10k Potentiometer
  • Breadboard
  • a bunch of wires


LCD example circuit

Before wiring the LCD screen to your Arduino we suggest to solder a PIN header strip to the 14 (or 16) PIN count connector of the LCD screen, as you can see in the image above. 
Wire your LCD screen to your Arduino, connect the following PINs:

  • LCD RS PIN to digital PIN 12
  • LCD Enable PIN to digital PIN 11
  • LCD D4 PIN to digital PIN 5
  • LCD D5 PIN to digital PIN 4
  • LCD D6 PIN to digital PIN 3
  • LCD D7 PIN to digital PIN 2

Additionally, connect a 10K Ohm potentiometer. 
The potentiometer has three pins. Connect the first pin to 5V, the middle pin to VO PIN (PIN3) of the LCD and finally the third pin to GND .


LCD example schematic


// Include the LiquidCrystal Library
#include <LiquidCrystal.h>
// Setup LCD PINs in order to use it
LiquidCrystal lcd_display(12, 11, 5, 4, 3, 2);
void setup() {
// Tell to the lcd object the LCD's number of columns and rows
lcd_display.begin(16, 2);
// Print a message to the LCD
void loop() {
// Move the cursor to column 0, line 1
// (remember that counting rows start from 0
// so line 1 is the 2nd row)
lcd_display.setCursor(0, 1);
// Print the number of seconds since start (or reset)