LCD I2C | Arduino Tutorial
Maybe your like
- TUTORIALS
- HARDWARE & TOOLS
- REFERENCES
- FAQs
- ABOUT US
SENSORS/ACTUATORS
- Arduino - Software Installization
- Arduino - Hardware Preparation
- Arduino - Hello World
- Arduino - Code Structure
- Arduino - Serial Monitor
- Arduino - Serial Plotter
- Arduino - LED - Blink
- Arduino - LED - Blink Without Delay
- Arduino - Blink multiple LED
- Arduino - LED - Fade
- Arduino - RGB LED
- Arduino - Traffic Light
- Arduino - Button
- Arduino - Button - Debounce
- Arduino - Button - Long Press Short Press
- Arduino multiple Button
- Arduino - Switch
- Arduino - Limit Switch
- Arduino - DIP Switch
- Arduino - Button - LED
- Arduino - Button - Relay
- Arduino - Button Toggle LED
- Arduino - Button Toggle Relay
- Arduino - Button - Piezo Buzzer
- Arduino - Button - Servo Motor
- Arduino - Potentiometer
- Arduino - Potentiometer fade LED
- Arduino - Potentiometer Triggers LED
- Arduino - Potentiometer Triggers Relay
- Arduino - Potentiometer Triggers Piezo Buzzer
- Arduino - Potentiometer Triggers Servo Motor
- Arduino - Rotary Encoder
- Arduino - Rotary Encoder LED
- Arduino - Rotary Encoder - Servo Motor
- Arduino - Piezo Buzzer
- Arduino - Buzzer
- Arduino - Motor
- Arduino - DC Motor
- Arduino - DC Motor - Limit Switch
- Arduino - Servo Motor
- Arduino - MG996R
- Arduino - Servo Motor controlled by Potentiometer
- Arduino - Light Sensor
- Arduino - LDR Module
- Arduino - Light Sensor Triggers LED
- Arduino - Light Sensor Triggers Relay
- Arduino - Light Sensor Triggers Servo Motor
- Arduino - Ultrasonic Sensor
- Arduino - Ultrasonic Sensor - LED
- Arduino - Ultrasonic Sensor - Relay
- Arduino - Ultrasonic Sensor - Piezo Buzzer
- Arduino - Ultrasonic Sensor - Servo Motor
- Arduino - Ultrasonic Sensor - LCD
- Arduino - Ultrasonic Sensor - OLED
- Arduino - Motion Sensor
- Arduino - Motion Sensor - LED
- Arduino - Motion Sensor - Relay
- Arduino - Motion Sensor - Piezo Buzzer
- Arduino - Motion Sensor - Servo Motor
- Arduino - Motion Sensor - MP3 Player
- Arduino - Motion Sensor - LED Strip
- Arduino - Relay
- Arduino - Relay Shield
- Arduino - 2-Channel Relay Module
- Arduino - 4-Channel Relay Module
- Arduino - Controls Fan
- Arduino - Controls Heating Element
- Arduino - Car
- Arduino - Actuator
- Arduino - Actuator with Feedback
- Arduino - Joystick
- Arduino - Joystick - Servo Motor
- Arduino - Soil Moisture Sensor
- Arduino - Soil Moisture Sensor Pump
- Arduino - Automatic Irrigation System
- Arduino - LCD
- Arduino - LCD I2C
- Arduino - LCD 20x4
- Arduino - LCD Keypad Shield
- Arduino - OLED
- Arduino - TFT LCD Display
- Arduino - TFT LCD Touch Screen Display
- Arduino - Round Circular TFT LCD Display
- Arduino - Button Count - OLED
- Arduino - Button Count - LCD
- Arduino - 74HC595 4-Digit 7-Segment Display
- Arduino - TM1637 4-Digit 7-Segment Display
- Arduino - LED Matrix
- Arduino - Bluetooth LED Matrix
- Arduino - LED Matrix via Web
- Arduino - Keypad
- Arduino - Keypad 1x4
- Arduino - Keypad - LCD
- Arduino - Keypad - Beep
- Arduino - Keypad - Buzzer
- Arduino - Keypad - Relay
- Arduino - Keypad - Servo Motor
- Arduino - Keypad - Solenoid Lock
- Arduino - Keypad - Electromagnetic Lock
- Arduino - Temperature Sensor
- Arduino - Temperature Sensor - LCD
- Arduino - Temperature Sensor - OLED
- Arduino - Temperature Sensor - LED Matrix
- Arduino - Temperature via Web
- Arduino - Temperature Sensor - Servo Motor
- Arduino - Temperature Sensor - Relay
- Arduino - DHT11
- Arduino - DHT22
- Arduino - Temperature Humidity Sensor
- Arduino - Temperature Humidity Sensor - LCD
- Arduino - Temperature Humidity Sensor - OLED Display
- Arduino - LM35 Temperature Sensor
- Arduino - TMP36 Temperature Sensor
- Arduino - Display Temperature from LM35 Sensor on OLED
- Arduino - Display Temperature from LM35 Sensor on LCD
- Arduino - Control Temperature
- Arduino - Cooling System using DHT Sensor
- Arduino - Cooling System using DS18B20 Temperature Sensor
- Arduino - Heating System
- Arduino - DHT11 - Relay
- Arduino - DHT11 - OLED
- Arduino - DHT11 - LCD
- Arduino - DHT22 - Relay
- Arduino - DHT22 - OLED
- Arduino - DHT22 - LCD
- Arduino - Touch Sensor
- Arduino - Touch Sensor - LED
- Arduino - Touch Sensor - Relay
- Arduino - Touch Sensor Toggle LED
- Arduino - Touch Sensor Toggle Relay
- Arduino - Touch Sensor - Piezo Buzzer
- Arduino - Touch Sensor - Servo Motor
- Arduino - Touch Sensor - Solenoid Lock
- Arduino - Door Sensor
- Arduino - Door Sensor - LED
- Arduino - Door Sensor - Relay
- Arduino - Door Sensor Toggle LED
- Arduino - Door Sensor Toggle Relay
- Arduino - Door Sensor - Piezo Buzzer
- Arduino - Door Sensor - Servo Motor
- Arduino - Solenoid Lock
- Arduino - Electromagnetic Lock
- Arduino - Button Controls Electromagnetic Lock
- Arduino - Keypad Door Lock
- Arduino - Door Lock System using Password
- Arduino - Controls Door Lock via Web
- Arduino - RFID/NFC
- Arduino - RFID/NFC - Relay
- Arduino - RFID/NFC - Servo Motor
- Arduino - RFID - Solenoid Lock
- Arduino - RFID - Electromagnetic Lock
- Arduino - RFID/NFC Door Lock System
- Arduino - RTC
- Arduino - DS1307 RTC Module
- Arduino - OLED Clock
- Arduino - LCD Clock
- Arduino - 7-segment Clock
- Arduino - Water Sensor
- Arduino - Water Leak Detector
- Arduino - Water Sensor Relay
- Arduino - Water Sensor Pump
- Arduino - Water/Liquid Valve
- Arduino - Controls Pump
- Arduino - Button - Pump
- Arduino - Rain Sensor
- Arduino - Rain Sensor - LED
- Arduino - Rain Sensor - Relay
- Arduino - Rain Sensor - Buzzer
- Arduino - Rain Sensor - Servo Motor
- Arduino - Measure Voltage
- Arduino - Sound Sensor
- Arduino - Sound Sensor - LED
- Arduino - Sound Sensor - Relay
- Arduino - Sound Sensor - Servo Motor
- Arduino - Force Sensor
- Arduino - Flame Sensor
- Arduino Fire Alarm
- Arduino - Gas Sensor
- Arduino - Gas Sensor - Relay
- Arduino - Infrared Obstacle Avoidance Sensor
- Arduino - Stepper Motor
- Arduino - Controls 28BYJ-48 Stepper Motor using ULN2003 Driver
- Arduino - Controls Stepper Motor using L298N Driver
- Arduino - DRV8825 Stepper Motor Driver
- Arduino - Stepper Motor and Limit Switch
- Arduino - GPS
- Arduino - LED Strip
- Arduino - NeoPixel LED Strip
- Arduino - WS2812B LED Strip
- Arduino - Dotstar Led Strip
- Arduino - Micro SD Card
- Arduino - Write Variable to SD Card
- Arduino - Log Data with Timestamp to SD Card
- Arduino - Read Config from SD Card
- Arduino - Audio
- Arduino - MP3 Player
- Arduino - RFID MP3 Player
- Arduino - Siren
- Arduino - SoftwareSerial
- Arduino RS232
- Arduino RS485
- Arduino RS422
- Arduino Serial to WiFi Converter
- Arduino RS232 to WiFi
- Arduino RS485 to WiFi
- Arduino RS422 to WiFi
- Arduino - IR Remote Control
- Arduino - Bluetooth
- Arduino - BLE
- Arduino controls Servo Motor via Bluetooth
- Arduino controls LED via Bluetooth
- How to get started with Arduino Uno R4
- Arduino Uno R4 WiFi controls LED via Web
- Arduino Uno R4 WiFi controls Relay via Web
- Arduino Uno R4 LED Matrix displays Number Character
INTERNET OF THING (IoT)
- Arduino - Ethernet
- Arduino - Ethernet Module
- Arduino - Ethernet Shield 2
- Arduino - PHPoC Shield
- Arduino - WiFi
- Arduino - TCP Client
- Arduino - Web Server
- Arduino - Web Server Multiple Pages
- Arduino - Web Server Password
- Arduino - WebSocket
- Arduino - Web Plotter
- Arduino - Controls Servo Motor via Web
- Arduino - Controls Car via Web
- Arduino - IoT
- Arduino - MQTT
- Arduino Shield
- Arduino - HTTP Request
- Arduino - HTTPS Request
- Arduino - MySQL
- Arduino - Modbus
- Communication between two Arduino
- Arduino to Arduino MQTT Communication
- Arduino - IFTTT
- Arduino - Make Voice Phone Call
- Arduino - Send SMS Message
- Arduino - Gmail
- Arduino - Door Open Email Notification
- Arduino - Motion Sensor Email Notification
- Arduino - Water Leak Email Notification
- Arduino - Secure Your Belongings: Detect Theft and Send Email Alerts
- Arduino - Send Email
- Arduino - Door Open - Send Email Notification
- Arduino - Temperature - Send Email Notification
LIBRARIES
- Arduino - Button Library
- Example - 01.Single Button
- Example - 02.Single Button Events
- Example - 03.Single Button Debounce
- Example - 04.Single Button All
- Example - 05.Multiple Button All
- Example - 06.Button Count
- Example - 07.Button Array
- Arduino - LED Library
- Example - LED Blink
- Example - LED Blink In Period
- Example - LED Blink Number Of Times
- Example - LED Fade In Fade Out
- Example - LED On Off
- Example - LED Toggle
- Example - Multiple LED
- Example - LED Array
- Arduino - Output Library
- Example - 01.On Off
- Example - 02.Toggle
- Example - 03.Single Blink Without Delay
- Example - 04.Single Blink Change Frequency
- Example - 05.Multiple Blink Without Delay
- Example - 06.Multiple Blink With Offset
- Example - 07.Blink In Period
- Example - 08.Pulse
- Arduino - Buzzer Library
- Example - Beep
- Example - Melody
- Example - Melody Repeat
- Arduino - Analog Keypad Library
- Example - Analog Keypad
- Example - Analog Button Array
In this Arduino LCD I2C tutorial, we will learn how to connect an LCD I2C (Liquid Crystal Display) to the Arduino board. LCDs are very popular and widely used in electronics projects for displaying information. There are many types of LCD. This tutorial takes LCD 16x2 (16 columns and 2 rows) as an example. The other LCDs are similar.
Hardware Required
| 1 | × | Official Arduino Uno |
| 1 | × | Alternatively, DIYables STEM V3, Fully Compatible with Arduino Uno R3 |
| 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 |
| 1 | × | Recommended: Screw Terminal Block Shield for Arduino Uno |
| 1 | × | Recommended: Breadboard Shield for Arduino Uno |
| 1 | × | Recommended: Enclosure for Arduino Uno |
| 1 | × | Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO |
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) |
| 1 | × | DIYables Sensor Kit (30 sensors/displays) |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
About LCD I2C 16x2
In the previous tutorial, we had learned how to use the normal LCD. However, wiring between Arduino and the normal LCD is complicated. Therefore, LCD I2C has been created to simplify the wiring. Actually, LCD I2C is composed of a normal LCD, an I2C module and a potentiometer.
Pinout
LCD I2C uses I2C interface, so it has 4 pins:
- GND pin: needs to be connected to GND (0V).
- VCC pin: the power supply for the LCD, needs to be connected to VCC (5V).
- SDA pin: I2C data signal
- SCL pin: I2C clock signal
LCD Coordinate
LCD I2C 16x2 includes 16 columns and 2 rows. the conlums and rows are indexed from 0.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
| LCD I2C | Arduino Uno, Nano | Arduino Mega |
|---|---|---|
| Vin | 5V | 5V |
| GND | GND | GND |
| SDA | A4 | 20 |
| SCL | A5 | 21 |
How To Program For LCD I2C
Thanks to the LiquidCrystal_I2C library, the using LCD is a piece of cake.
- Include the library:
- Declare a LiquidCrystal_I2C object with I2C address, the number of columns, the number of rows:
- Initialize the LCD.
- Move cursor to the desired position (column_index, row_index)
- Print a message to the LCD.
There are many things more that we can do with LCD (see Do More with LCD part)
※ NOTE THAT:
The I2C address of LCD can vary according to the manufacturers. In the code, we used 0x27 that is specified by DIYables brand
Arduino Code
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows void setup() { lcd.init(); // initialize the lcd lcd.backlight(); } void loop() { lcd.clear(); // clear display lcd.setCursor(0, 0); // move cursor to (0, 0) lcd.print("Arduino"); // print message at (0, 0) lcd.setCursor(2, 1); // move cursor to (2, 1) lcd.print("GetStarted.com"); // print message at (2, 1) delay(2000); // display the above for two seconds lcd.clear(); // clear display lcd.setCursor(3, 0); // move cursor to (3, 0) lcd.print("DIYables"); // print message at (3, 0) lcd.setCursor(0, 1); // move cursor to (0, 1) lcd.print("www.diyables.io"); // print message at (0, 1) delay(2000); // display the above for two seconds }Quick Steps
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "LiquidCrystal I2C", then find the LiquidCrystal_I2C library by Frank de Brabander
- Click Install button to install LiquidCrystal_I2C library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- See the result on LCD
image source: diyables.io - Try modifying text and position
LCD I2C Selection Guide
There are various types of LCD I2C displays available in the market, mainly differing in background color and the shape of the I2C interface module.
Regarding color, these displays usually come in two background colors: green and blue.
For the I2C interface module shape, there are two main aspects to consider:
- Potentiometer size: This includes options for thin and thick potentiometers.
- Thick potentiometer: Easier to adjust but occupies more space.
- Thin potentiometer: More compact, saving space with its smaller height.
- I2C selection jumper:
- With jumper: Allows switching between two I2C addresses, useful when your code uses two LCD displays simultaneously. However, it can cause confusion with I2C addresses when only one LCD is used and it also requires more space.
- Without jumper: This has a fixed I2C address and is very convenient when your code uses just one LCD display. Since most applications use only one LCD, this type is highly recommended.
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
Do More with LCD
Custom Character
lcd.print() function supports only ASCII characters. If you want to display a special character or symbol (e.g. heart, angry bird), you need to use the below character generator.
LCD 16x2 can display 32 characters (2 rows and 16 columns). Each character is composed of 40 pixels (8 rows and 5 columns).
The character generator represents a character (40 pixels). You just need to do the following steps:
Click on each pixel to select/deselect Clear Copy below custom character code Replace the customChar[8] in the below code #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows byte customChar[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000 }; void setup() { lcd.init(); // initialize the lcd lcd.backlight(); lcd.createChar(0, customChar); // create a new custom character lcd.setCursor(2, 0); // move cursor to (2, 0) lcd.write((byte)0); // print the custom char at (2, 0) } void loop() { }Result on LCD:
Multiple custom characters
We can create up to 8 custom characters (indexed 0 to 7). The below example creates and displays three characters.
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows byte customChar0[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000 }; byte customChar1[8] = { 0b00100, 0b01110, 0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100 }; byte customChar2[8] = { 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b11111, 0b01110, 0b00100 }; void setup() { lcd.init(); // initialize the lcd lcd.backlight(); lcd.createChar(0, customChar0); // create a new custom character (index 0) lcd.createChar(1, customChar1); // create a new custom character (index 1) lcd.createChar(2, customChar2); // create a new custom character (index 2) lcd.setCursor(2, 0); // move cursor to (2, 0) lcd.write((byte)0); // print the custom char 0 at (2, 0) lcd.setCursor(4, 0); // move cursor to (4, 0) lcd.write((byte)1); // print the custom char 1 at (4, 0) lcd.setCursor(6, 0); // move cursor to (6, 0) lcd.write((byte)2); // print the custom char 2 at (6, 0) } void loop() { }Result on LCD:
Summary: how to use custom character on LCD
- Use the above character generator to create binary code for the custom character.
- Declare the binary code for the custom character (copy from above step)
- Create custom character and assign to an index value (from 0 to 7) in setup() function
- Print the custom character in LCD anytime, anywhere (in setup() or loop() function)
Other functions
Add the below functions into loop() function one by one. And add delay(5000) after each function
- Clear LCD screen
- Move the cursor to the upper-left of the LCD
- Move the cursor to the a position (column, row)
- Display the LCD cursor
- Hides the LCD cursor.
- Display the blinking LCD cursor
- Turns off the blinking LCD cursor.
- And more at LiquidCrystal Library Reference
Challenge Yourself
Use LCD to do one of the following projects:
- Sending text from PC (via Serial Monitor) and display on LCD. Hint: Refer to How to send data from PC to Aduino
- Displaying the pressed key of the keypad on LCD. Hint: Refer to Arduino - Keypad
Troubleshooting on LCD I2C
If the text is not displayed on LCD I2C, please check the following issues:
- Adjust the brightness of LCD by rotating potentiometer in the backside of LCD
- Depending on manufacturers, the I2C address of LCD may be different. Usually, the default I2C address of LCD is 0x27 or 0x3F. Try these values one by one. If you still failed, run the below code to find the I2C address.
The result on Serial Monitor:
COM6 Send Scanning... I2C device found at address 0x3F ! done Scanning... I2C device found at address 0x3F ! done Autoscroll Show timestamp Clear output 9600 baud NewlineThe Best Arduino Starter Kit
- See the best Arduino kit for beginner
See Also
- Arduino - LCD
- Arduino - LCD 20x4
- Arduino - LCD Keypad Shield
- Arduino - OLED
- Arduino - TFT LCD Display
- Arduino - TFT LCD Touch Screen Display
- Arduino - Round Circular TFT LCD Display
- Arduino - Button Count - OLED
- Arduino - Button Count - LCD
- Arduino - Ultrasonic Sensor - LCD
- Arduino - Ultrasonic Sensor - OLED
- Arduino - LED Matrix
- Arduino - LED Matrix via Web
- Arduino - Keypad - LCD
- Arduino - Temperature Sensor - LCD
- Arduino - Temperature Sensor - OLED
- Arduino - Temperature Sensor - LED Matrix
- Arduino - Temperature Humidity Sensor - LCD
- Arduino - Temperature Humidity Sensor - OLED Display
- Arduino - Display Temperature from LM35 Sensor on OLED
- Arduino - Display Temperature from LM35 Sensor on LCD
- Arduino - DHT11 - OLED
- Arduino - DHT11 - LCD
- Arduino - DHT22 - OLED
- Arduino - DHT22 - LCD
- Arduino - Door Lock System using Password
- Arduino - OLED Clock
- Arduino - LCD Clock
※ OUR MESSAGES
- We are AVAILABLE for HIRE. See how to hire us to build your project
- If this tutorial is useful for you, please give us motivation to make more tutorials.
- You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
TABLE OF CONTENTS
- Hardware Required
- About LCD I2C 16x2
- Wiring Diagram
- How To Program For LCD I2C
- Arduino Code
- LCD I2C Selection Guide
- Video
- Do More with LCD
- Challenge Yourself
- Troubleshooting on LCD I2C
- The Best Arduino Starter Kit
- See Also
Tag » Arduino I2c Lcd 2004 Example
-
Character I2C LCD With Arduino Tutorial (8 Examples)
-
Library And Arduino Code For LCD2004 Display With I2C - Robojax
-
Introduction To LCD2004 LCD Display With I2C Module For Arduino
-
Example Of 20x4 LCD With I2C That Works? - Displays - Arduino Forum
-
How To Use A 20x4 I2C Character LCD Display With Arduino
-
LCD 2004 (20x4) I2C Library - Displays - Arduino Forum
-
[SOLVED] I2C MH + LCD 2004A + Arduino Uno Display Issues ...
-
I2C LCD On Arduino - Stunningly Easily Setup And Control
-
How To Use I2C Serial LCD 20X4 (Yellow Backlight) - Instructables
-
In-Depth: Interfacing An I2C LCD With Arduino
-
I2C LCD With ESP32 On Arduino IDE - ESP8266 Compatible
-
Using A 20x4 I2C Character LCD Display With Arduino Uno
-
Hiển Thị Thời Gian Thực Lên LCD 20x4 I2C Dùng Arduino