Liquid Crystal Display (LCD)
Interfacing 16x2 LCD Display with Arduino UNO and ESP32 using I2C
Interfacing 16x2 LCD Display with Arduino UNO and ESP32 using I2C demonstrates how a 16x2 Liquid Crystal Display (LCD) can be interfaced with microcontroller development boards to display text and messages.
An LCD is an electronic display module commonly used to display alphanumeric characters, numbers and symbols.
In this experiment, a 16x2 LCD with an I2C interface is connected to Arduino UNO and ESP32 separately. The I2C communication protocol is used to transfer data between the microcontroller and the LCD module.
The experiment demonstrates displaying messages on the LCD using Arduino IDE programming.
Microcontroller → I2C Communication → 16x2 LCD → Text Display
Theory
A 16x2 LCD (Liquid Crystal Display) is an electronic display module capable of displaying 16 characters per line and 2 lines of text.
The LCD consists of liquid crystal cells arranged in a matrix. These cells control the passage of light to display alphanumeric characters.
The LCD module used in this experiment is equipped with an I2C interface module, which simplifies the connection between the LCD and the microcontroller.
I2C stands for Inter-Integrated Circuit. It is a serial communication protocol that uses two communication lines:
- SDA (Serial Data): Used for transferring data between devices.
- SCL (Serial Clock): Used for synchronizing data communication.
The I2C interface reduces the number of connections required between the microcontroller and the LCD.
The LCD module generally uses the I2C address 0x27. The address may vary depending on the I2C module.
The LiquidCrystal_I2C library is used in Arduino IDE to control the LCD display.
The library provides functions such as:
| Function | Description |
|---|---|
| lcd.init() | Initializes the LCD display |
| lcd.begin() | Initializes the LCD using the supported library interface |
| lcd.backlight() | Turns ON the LCD backlight |
| lcd.print() | Displays text or data on the LCD |
| lcd.setCursor() | Sets the cursor position on the LCD |
| lcd.clear() | Clears the LCD display |
I2C SDA + SCL → LCD Communication → Character Display
Applications
16x2 LCD displays are commonly used in:
- Embedded system projects
- Industrial monitoring systems
- Home automation systems
- Temperature monitoring systems
- Digital measurement instruments
- Electronic control panels
- IoT-based monitoring systems
Interfacing 16x2 LCD with Arduino UNO
Connections
The 16x2 LCD with I2C interface is connected to the Arduino UNO using the I2C communication pins.
The following connections are used:
| LCD I2C Module | Arduino UNO | Function |
|---|---|---|
| VCC | 5V | Power supply |
| GND | GND | Ground |
| SDA | A4 | Serial Data |
| SCL | A5 | Serial Clock |
Arduino UNO I2C Pin Details:
| Parameter | Arduino UNO |
|---|---|
| SDA | A4 |
| SCL | A5 |
| Operating Logic Voltage | 5V |
| LCD I2C Address | 0x27 (as specified in the program) |
Algorithm
The following algorithm is used to interface the 16x2 LCD with Arduino UNO:
- Start the Arduino IDE.
- Connect the Arduino UNO board to the computer using a USB cable.
- Connect the 16x2 LCD I2C module to the Arduino UNO.
- Include the Wire.h and LiquidCrystal_I2C.h libraries.
- Create an LCD object with I2C address 0x27 and display dimensions of 16 columns and 2 rows.
- In the void setup() function, initialize the LCD.
- Turn ON the LCD backlight.
- Display the message "Hello, World!" on the LCD.
- Set the cursor position for displaying the next message.
- Display the message "Uno Here :)" on the second row.
- Keep the LCD display active.
Working
The Arduino UNO communicates with the 16x2 LCD through the I2C interface.
The working sequence is:
- The Arduino UNO initializes the I2C communication interface.
- The LCD module is initialized using the LiquidCrystal_I2C library.
- The LCD backlight is turned ON.
- The message "Hello, World!" is displayed on the first row.
- The cursor is moved to the second row.
- The message "Uno Here :)" is displayed on the second row.
- The displayed messages remain visible on the LCD.
Arduino UNO → I2C Communication → 16x2 LCD → Message Display
Arduino UNO Program Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Change the address based on the scanner output
LiquidCrystal_I2C lcd(0x27, 16, 2);
//5V -> 5V
//GND -> GND
//SDA -> A4
//SCL -> A5
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, World!");
lcd.setCursor(0, 1);
lcd.print("Uno Here :)");
}
void loop() {}
Program Explanation
- The Wire.h library is included for I2C communication.
- The LiquidCrystal_I2C.h library is included to control the LCD display.
- The LCD object is created using the I2C address 0x27 with 16 columns and 2 rows.
- The lcd.init() function initializes the LCD display.
- The lcd.backlight() function turns ON the LCD backlight.
- The lcd.setCursor(0, 0) function positions the cursor at the first column of the first row.
- The lcd.print("Hello, World!") function displays the message "Hello, World!" on the first row.
- The lcd.setCursor(0, 1) function positions the cursor at the first column of the second row.
- The lcd.print("Uno Here :)") function displays the message "Uno Here :)" on the second row.
- The loop() function is empty because the messages are displayed only once during initialization and remain visible.
Observation
When the Arduino UNO is connected to the 16x2 LCD using the I2C interface, the LCD initializes successfully and displays the programmed messages.
The following output is displayed:
Hello, World!
Uno Here :)
Conclusion
The Arduino UNO successfully interfaces with the 16x2 LCD using the I2C communication protocol.
The LCD displays "Hello, World!" on the first row and "Uno Here :)" on the second row.
Thus, text display using a 16x2 I2C LCD and Arduino UNO is successfully implemented.
Interfacing 16x2 LCD with ESP32
Connections
The 16x2 LCD with I2C interface is connected to the ESP32 using its I2C communication pins.
The following connections are used:
| LCD I2C Module | ESP32 | Function |
|---|---|---|
| VCC | 3.3V (subject to module compatibility) | Power supply |
| GND | GND | Ground |
| SDA | GPIO 21 | Serial Data |
| SCL | GPIO 22 | Serial Clock |
ESP32 I2C Pin Details:
| Parameter | ESP32 |
|---|---|
| SDA | GPIO 21 |
| SCL | GPIO 22 |
| Logic Voltage | 3.3V |
| LCD I2C Address | 0x27 (as specified in the program) |
Note: Check the LCD I2C module's supply voltage requirements and I2C pull-up voltage before connecting it to the ESP32. Many LCD backpacks operate at 5V and have pull-up resistors connected to their supply voltage. Ensure that the ESP32 GPIO pins are never exposed to 5V.
Algorithm
The following algorithm is used to interface the 16x2 LCD with ESP32:
- Start the Arduino IDE.
- Connect the ESP32 development board to the computer using a USB cable.
- Connect the 16x2 LCD I2C module to the ESP32.
- Include the Wire.h and LiquidCrystal_I2C.h libraries.
- Create an LCD object with I2C address 0x27 and display dimensions of 16 columns and 2 rows.
- In the void setup() function, initialize the LCD.
- Turn ON the LCD backlight.
- Display the message "Hello world!" on the LCD.
- Provide a delay of 500 milliseconds.
- In the void loop() function, clear the LCD display.
- Set the cursor position to column 2 and row 0.
- Display the message "Good".
- Set the cursor position to column 6 and row 0.
- Display the message "Morning".
- Provide a delay of 500 milliseconds.
- Repeat the process continuously.
Working
The ESP32 communicates with the 16x2 LCD through the I2C communication interface.
The working sequence is:
- The ESP32 initializes the LCD using the LiquidCrystal_I2C library.
- The LCD backlight is turned ON.
- The message "Hello world!" is displayed.
- A delay of 500 milliseconds is provided.
- The LCD display is cleared.
- The cursor is positioned at column 2 of the first row.
- The message "Good" is displayed.
- The cursor is moved to column 6 of the first row.
- The message "Morning" is displayed.
- A delay of 500 milliseconds is provided.
- The process repeats continuously.
ESP32 → I2C Communication → 16x2 LCD → Text Display
ESP32 Program Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//scl 22
//sda 21
// Set the LCD address to 0x27 for a 16 columns and 2 rows LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();//Use this method for Arduino UNO
lcd.backlight();// Turn on the blacklight and print a message.
lcd.print("Hello world!");
delay(500);
}
void loop()
{
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Good");
lcd.setCursor(6, 0);
lcd.print("Morning");
delay(500);
}
Program Explanation
- The Wire.h library is included for I2C communication.
- The LiquidCrystal_I2C.h library is included to control the LCD display.
- The LCD object is created with I2C address 0x27 and dimensions of 16 columns and 2 rows.
- The comments specify GPIO 22 as SCL and GPIO 21 as SDA.
- The lcd.begin() function is used to initialize the LCD display.
- The lcd.backlight() function turns ON the LCD backlight.
- The lcd.print("Hello world!") function displays the message "Hello world!" on the LCD.
- The delay(500) function provides a delay of 500 milliseconds.
- The lcd.clear() function clears the LCD display.
- The lcd.setCursor(2, 0) function positions the cursor at column 2 of the first row.
- The lcd.print("Good") function displays the text "Good".
- The lcd.setCursor(6, 0) function positions the cursor at column 6 of the first row.
- The lcd.print("Morning") function displays the text "Morning".
- The delay(500) function provides a delay of 500 milliseconds before the next iteration.
- The loop() function continuously repeats the display operation.
Observation
When the ESP32 is connected to the 16x2 LCD using the I2C interface, the LCD initializes and displays the programmed messages.
Initially, the message "Hello world!" is displayed for 500 milliseconds.
After that, the LCD displays "Good Morning" on the first row. The display is cleared and updated repeatedly.
The following output is displayed during the loop operation:
Good Morning
Conclusion
The ESP32 successfully interfaces with the 16x2 LCD using the I2C communication protocol.
The LCD displays the initial message "Hello world!" and subsequently displays "Good Morning" through continuous execution of the loop() function.
Thus, text display using a 16x2 I2C LCD and ESP32 is successfully implemented.
Result
The 16x2 I2C LCD is successfully interfaced with both Arduino UNO and ESP32 development boards.
The Arduino UNO displays static messages on the LCD, while the ESP32 continuously updates the displayed text using the lcd.clear(), lcd.setCursor() and lcd.print() functions.
Thus, LCD interfacing using the I2C communication protocol is successfully demonstrated with both microcontroller platforms.