ESP8266 - LCD 20x4

This tutorial instructs you how to use LCD 20x4 display with ESP8266, how to program for ESP8266 to display text on LCD 20x4.

Hardware Preparation

1×ESP8266 NodeMCU
1×USB A to Mini-B USB cable
1×LCD 20x4
1×Jumper Wires
1×(Optional) 9V Power Adapter for ESP8266
1×(Optional) ESP8266 Screw Terminal Adapter

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of LCD I2C 20x4

LCD I2C is made up of a standard LCD, an I2C module and a potentiometer.

The LCD Pinout

The LCD I2C 20x4 uses the I2C interface to connect to ESP8266. It has four pins:

  • The GND pin needs to be connected to ground (0V).
  • The VCC pin is the power supply for the LCD and must be connected to VCC (5V).
  • The SDA pin is the I2C data signal.
  • The SCL pin is the I2C clock signal.
LCD I2C pinout

LCD Coordinate

The LCD I2C 20x4 has 20 columns and 4 rows, with the columns and rows being numbered starting from 0.

ESP8266 NodeMCU LCD I2C coordinate

Wiring Diagram

The wiring diagram between ESP8266 NodeMCU and LCD I2C

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

Vin Vin

How To Program For LCD I2C

The LiquidCrystal_I2C library needs to be included in order to use the LCD.

  • Set up the LCD:

The LCD must be set up properly for it to work correctly.

  • Write to the LCD:

Writing to the LCD is easy thanks to the LiquidCrystal_I2C library.

#include <LiquidCrystal_I2C.h> // Library for LCD
  • Create a LiquidCrystal_I2C object with an I2C address, the number of columns, and the number of rows specified.
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 20 column and 4 rows
  • Start up the LCD.
lcd.init(); //initialize the lcd lcd.backlight(); //open the backlight
  • Go to the column and row indicated by column_index and row_index respectively.
lcd.setCursor(column_index, row_index);
  • Display a message on the LCD.
lcd.print("Hello World!");

Explore the possibilities of what can be achieved with LCD by looking at the "Do More with LCD" section.


The address of the LCD may differ depending on the manufacturer. For our code, we used 0x27 as specified by DIYables.

ESP8266 Code

/* * This ESP8266 NodeMCU code was developed by * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * */ #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address 0x27, 20 column and 4 rows void setup() { lcd.init(); // Initialize the LCD I2C display lcd.backlight(); lcd.setCursor(0, 0); // move cursor the 1st row lcd.print("LCD 20x4"); // print message at the 1st row lcd.setCursor(0, 1); // move cursor to the 2nd row lcd.print("I2C Address: 0x27"); // print message at the 2nd row lcd.setCursor(0, 2); // move cursor to the 3rd row lcd.print("DIYables"); // print message at the 3rd row lcd.setCursor(0, 3); // move cursor to the 4th row lcd.print(""); // print message the 4th row } void loop() { }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Click to the Libraries icon on the left bar of the Arduino IDE.
  • Search for "LiquidCrystal I2C" and locate the LiquidCrystal_I2C library created by Frank de Brabander.
  • Then, click the Install button to add the library.
ESP8266 NodeMCU LiquidCrystal I2C library
  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button in the IDE to send the code to the ESP8266.
  • Check the LCD for the result.
  • Experiment with altering the text and its location.

LCD I2C Selection Guide

There are different types of LCD I2C displays you can buy. They mainly differ in background color and how you select the I2C address.

LCD I2C 20x4 Selection Guide

For Color Options: Usually, there are two background colors available: green and blue.

For I2C Address Selection:

  • With a jumper: This option lets you switch between two I2C addresses, which is helpful if you use two LCDs at the same time. But if your code uses only one LCD, it can cause confusion with I2C addresses. It also takes up more space.
  • Without a jumper: This option has a fixed I2C address, making it very easy to use when your project uses only one LCD. Since most projects use just one LCD, this type is recommended.

Video Tutorial

Do More with LCD

Custom Character

See Custom characters on LCD


  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!