Arduino Mega - LCD 20x4
This guide shows you how to use a 20x4 LCD screen with an Arduino Mega board through an I2C connection. In detail, we will learn:
- How to connect a 20x4 I2C LCD to an Arduino Mega
- How to program an Arduino Mega to show text on a 20x4 I2C LCD

Hardware Preparation
| 1 | × | Arduino Mega | |
| 1 | × | USB 2.0 cable type A/B (for USB-A PC) | |
| 1 | × | USB 2.0 cable type C/B (for USB-C PC) | |
| 1 | × | LCD 20x4 | |
| 1 | × | Jumper Wires |
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (30 sensors/displays) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of LCD I2C 20x4
Pinout
The 20x4 I2C LCD uses the I2C bus and has 4 pins:
- GND pin: connect to ground (0V).
- VCC pin: connect to +5V to power the LCD.
- SDA pin: I2C data line.
- SCL pin: I2C clock line.

LCD Coordinate
The I2C LCD 20x4 screen has 20 columns and 4 rows. The columns and rows start at 0.

Wiring Diagram

This image is created using Fritzing. Click to enlarge image
| LCD I2C | Arduino Mega, Nano | Arduino Mega |
|---|---|---|
| Vin | 5V | 5V |
| GND | GND | GND |
| SDA | A4 | 20 |
| SCL | A5 | 21 |
How To Program For LCD I2C
It's easy to use the LCD with the LiquidCrystal_I2C library.
- Install the library:
- Create a LiquidCrystal_I2C object using the I2C address, the number of columns, and the number of rows:
- Set up the LCD display.
- Put the cursor at the place given by column_index and row_index.
- Show a message on the LCD screen.
※ NOTE THAT:
Different brands use different I2C addresses for the LCD. In our example, we used 0x27, the address given by the maker DIYables (https://diyables.io/products/lcd-20x4-display-i2c-interface).
Arduino Mega Code
Detailed Instructions
Follow these steps one by one.
- Connect the LCD I2C 20x4 to the Arduino Mega according to the provided diagram.
- Connect the Arduino Mega to your computer with a USB cable.
- Open the Arduino IDE on your computer.
- Select the correct Arduino Mega board and the serial port.
- Click the Libraries icon on the left side of the Arduino IDE.
- Type "LiquidCrystal I2C" and find the LiquidCrystal_I2C library by Frank de Brabander.
- Click Install to add the LiquidCrystal_I2C library.

- Copy the code shown above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Mega.
- Check the LCD to see the result.
- Try changing the text and where it appears.
Your Arduino Mega board might not give the LCD enough power. If the LCD is not bright or can't display characters, use an external power source for the LCD.