ESP32 - LCD

This tutorial instructs you how to use ESP32 with LCD I2C. In detail, we will learn:

Hardware Used In This Tutorial

1×ESP-WROOM-32 Dev Module
1×USB Cable Type-C
1×LCD I2C
1×Breadboard
1×Jumper Wires
1×(Optional) DC Power Jack
1×(Recommended) Screw Terminal Expansion Board for ESP32
1×(Recommended) Power Splitter For ESP32

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 in this section are Amazon affiliate links, meaning we may earn a commission at no additional cost to you if you make a purchase through them. Additionally, some links direct you to products from our own brand, DIYables.

Introduction to LCD I2C 16x2

LCD I2C Pinout

LCD I2C has 4 pins:

  • VCC pin: the power supply for the LCD, needs to be connected to VCC (5V).
  • GND pin: connect this pin to GND (0V).
  • SCL pin: I2C clock signal pin
  • SDA pin: I2C data signal pin
LCD I2C Pinout

LCD 16x2 Coordinates

LCD I2C 16x2 has 2 rows and 16 columns indexed from 0.

ESP32 LCD I2C Coordinate

Wiring Diagram between LCD I2C and ESP32

  • How to connect ESP32 and LCD i2c using breadboard (powered via USB cable)
ESP32 LCD I2C Wiring Diagram

This image is created using Fritzing. Click to enlarge image

  • How to connect ESP32 and LCD i2c using breadboard (powered via Vin pin)
ESP32 LCD display Wiring Diagram

This image is created using Fritzing. Click to enlarge image

How to connect ESP32 and LCD i2c
How to wire ESP32 and LCD i2c

If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: How to Power ESP32.

How To Program LCD I2C using ESP32

  • Include the LiquidCrystal_I2C library:
#include <LiquidCrystal_I2C.h>
  • Declare a LiquidCrystal_I2C object:
LiquidCrystal_I2C lcd_i2c(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
  • Initialize the LCD.
lcd_i2c.init(); lcd_i2c.backlight();
  • Move cursor to the desired position (column_index, row_index)
lcd_i2c.setCursor(column_index, row_index);
  • Print a message to the LCD.
lcd_i2c.print("Hello ESP32!");

※ NOTE THAT:

The LCD I2C address can be different from each manufacturer. In the code, we used address of 0x27 that is specified by DIYables manufacturer

ESP32 Code

#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows void setup() { lcd_i2c.init(); // initialize the lcd lcd_i2c.backlight(); } void loop() { lcd_i2c.clear(); // clear display lcd_i2c.setCursor(0, 0); // move cursor to (0, 0) lcd_i2c.print("Hello"); // print message at (0, 0) lcd_i2c.setCursor(2, 1); // move cursor to (2, 1) lcd_i2c.print("esp32io.com"); // print message at (2, 1) delay(2000); // display the above for two seconds lcd_i2c.clear(); // clear display lcd_i2c.setCursor(3, 0); // move cursor to (3, 0) lcd_i2c.print("DIYables"); // print message at (3, 0) lcd_i2c.setCursor(0, 1); // move cursor to (0, 1) lcd_i2c.print("www.diyables.io"); // print message at (0, 1) delay(2000); // display the above for two seconds }

Quick Instructions

  • If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
  • Click to the Libraries icon on the left bar of the Arduino IDE.
  • Type “LiquidCrystal I2C” on the search box, then look for the LiquidCrystal_I2C library by Frank de Brabander
  • Click Install button to install LiquidCrystal_I2C library.
ESP32 LiquidCrystal I2C library
  • Copy the above code and paste it to Arduino IDE.
  • Compile and upload code to ESP32 board by clicking Upload button on Arduino IDE
  • See the result on LCD
ESP32 LCD I2C display
  • Try modifying text and position

LCD I2C Selection Guide

There are many types of LCD I2C displays available. They mainly differ in background color and the design of the I2C interface module.

LCD I2C Selection Guide

Regarding color, these displays usually have either a green or blue background.

For the I2C interface module design, there are two main factors to consider:

  • Potentiometer size: You can choose between thin and thick potentiometers.
    • Thick potentiometer: Easier to adjust but takes up more space.
    • Thin potentiometer: More compact, saving space due to its smaller height.
  • I2C selection jumper:
    • With jumper: Allows switching between two I2C addresses, which is useful when using two LCD displays at the same time. However, it can cause confusion with I2C addresses when using only one LCD and also requires more space.
    • Without jumper: Has a fixed I2C address and is very convenient for using just one LCD display. Since most applications use only one LCD, this type is highly recommended.

Video Tutorial

Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.

Do More with LCD

Custom Character

If you want to display special characters or symbols (e.g. emoticon), see how to display the special characters on LCD.

Troubleshooting on LCD I2C

If LCD does not display anything, please see LCD does not work!- Checklist

※ OUR MESSAGES