Arduino Nano ESP32 - LCD

This tutorial provides instructions on how to use Arduino Nano ESP32 with LCD I2C. In detail, we will learn:

Hardware Preparation

1×Arduino Nano ESP32
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 Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano
1×(Recommended) Power Splitter For Arduino Nano 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 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.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of 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.

Arduino Nano ESP32 LCD I2C Coordinate

Wiring Diagram between LCD I2C and Arduino Nano ESP32

  • When powering the Arduino Nano ESP32 board via USB port.
The wiring diagram between Arduino Nano ESP32 and LCD I2C

This image is created using Fritzing. Click to enlarge image

  • When powering the Arduino Nano ESP32 board via Vin pin.
The wiring diagram between Arduino Nano ESP32 and LCD I2C 5V power source

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

When powering the Arduino Nano ESP32 through the USB port, it is possible to power the LCD display using the VBUS pin of the Arduino Nano ESP32, eliminating the need for an external power source. However, it is important to note that this approach may not work as the power provided by the VBUS pin might be insufficient for the proper functioning of the LCD display.

How To Program LCD I2C using Arduino Nano 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

Arduino Nano 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 I2C display 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("newbiely.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 }

Detailed Instructions

  • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
  • Open the Library Manager by clicking on the Library Manager icon on the left navigation bar of 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.
Arduino Nano ESP32 LiquidCrystal I2C library
  • Copy the above code and paste it to Arduino IDE.
  • Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
  • See the result on LCD
  • Try modifying text and position

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

  • 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!