Arduino Mega - LCD I2C
- How to connect the LCD I2C to the Arduino Mega
- How to program the Arduino Mega to show text on the LCD via I2C
- How to program the Arduino Mega to show numbers on the LCD via I2C
- How to program the Arduino Mega to show custom characters on the LCD via I2C
- We give clear steps, code, wiring diagrams, video tutorials, and easy explanations of each line of code to help you start using the Arduino Mega quickly
- Explore these guides and more at Newbiely.com.
This guide shows you how to use a 16x2 LCD with an I2C connection on an Arduino Mega. In simple terms, we will learn:
- How to connect an I2C LCD to an Arduino Mega
- How to program the Arduino Mega to display text on the I2C LCD
- How to program the Arduino Mega to display numbers on the I2C LCD
- How to program the Arduino Mega to display custom characters on the 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 I2C | |
| 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 16x2
The 16x2 LCD I2C is a small screen with 16 columns and 2 lines. It has an I2C connection and a small knob to adjust the contrast.
Pinout
The LCD I2C uses an I2C bus and has 4 pins.
- GND pin: connect to ground (0 volts).
- VCC pin: connect to power (5 volts).
- SDA pin: carries the I2C data line.
- SCL pin: carries the I2C clock line.

LCD Coordinate
The LCD I2C 16x2 screen has 16 columns and 2 rows. The columns and rows both start counting from 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
The LiquidCrystal_I2C library makes the LCD easy to use.
- Add the library:
- Make a LiquidCrystal_I2C object by giving its I2C address, the number of columns, and the number of rows.
- Set up the LCD display.
- Put the cursor at the spot you chose (column_index, row_index).
- Show a message on the LCD screen.
We can do lots more with an LCD. See the Do More with LCD section.
※ NOTE THAT:
The I2C address of the LCD can be different depending on who made it. In our code, we used 0x27, as the manufacturer says (DIYables: https://diyables.io/products/lcd-i2c-16x2).
Arduino Mega Code
Detailed Instructions
Do these steps one by one.
- Connect the LCD I2C display to the Arduino Mega according to the diagram.
- Connect the Arduino Mega to your computer with a USB cable.
- Open the Arduino IDE on your computer.
- Choose Arduino Mega as the board and select the COM port.
- Click the Libraries icon on the left side of the IDE.
- In the search box, type "LiquidCrystal I2C" and find the LiquidCrystal_I2C library by Frank de Brabander.
- Click Install to install the LiquidCrystal_I2C library.

- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to upload the code to the Arduino Mega.
- See the result on the LCD screen.
- Try changing the text and where it is.
Video Tutorial
Do More with LCD
Custom Character
To show special symbols like a heart or an angry bird on an LCD screen, you need to use the character generator, because lcd.print() can only display ASCII characters.
An LCD 16x2 display can show 32 characters in total on 2 lines, with 16 characters on each line. Each character uses 40 small dots, arranged in 8 rows and 5 columns.
The character maker creates a character (40 pixels). Just follow these steps:
Result shown on the screen:

Multiple custom characters
We can create up to eight special characters (numbered from 0 to 7). The example below shows how to create and show three characters.
Result shown on the LCD screen:

Summary: how to use custom character on LCD
- Use the tool above to create the binary code for your character.
- Write down the binary code for your character (copy it from the previous step).
- Create your own character and place it at a number between 0 and 7 in the setup() function.
- Show a special symbol on the LCD whenever you want, in setup() or in loop().
Other functions
Add these functions to the loop() function one at a time, and pause for five seconds after each function.
- Clear LCD screen
- Put the cursor in the top left corner of the screen.
- Move the cursor to a specific position (column and row).
- Show the cursor on the LCD screen.
- Turn off the cursor on the LCD screen.
- Show the blinking cursor on the LCD screen.
- Stops the blinking cursor on the LCD screen.
- Get more information from the LiquidCrystal Library Reference: https://arduinogetstarted.com/reference/library/arduino-lcd-library
Troubleshooting on LCD I2C
If the text does not show on the LCD I2C, please check these things:
- Change the LCD brightness by turning the small pot on the back.
- The LCD's I2C address can be different for different brands. It is usually 0x27 or 0x3F. Try these addresses one by one. If neither works, use the following code to find the correct I2C address.
The result shown on the Serial Monitor: