How to interface I2C LCD display with Arduino ?
Last Updated :
20 Mar, 2023
In this article, we will learn how to interface LCD displays with Arduino Uno R3.
Arduino is an open-source electronics platform. It consists ATmega328P 8-bit Microcontroller. It can be able to read inputs from different sensors & we can send instructions to the microcontroller in the Arduino. It provides Arduino IDE to write code & connect the hardware devices like Arduino boards & sensors.
LCD Display:
LCD stands for Liquid Crystal Display. LCD is a flat-paneled display. It uses liquid crystals combined with polarized to display the content. LCD uses the light modulation property of LCD. LCD is available both in Monochrome and Multicolor. It cannot emit light directly without a backlight. In some LCDs, It displays the content only with the help of a backlight in a dark place.
I2C communication:
I2C or IIC stands for Inter-Integrated Communication. I2C is a serial communication interface to communicate with other I2C devices. I2C uses multi-master / multi slave method. I2C uses 2 lines named SCL and SDA for transmission/reception and another 2 lines for power supply and ground. Each and every I2C device has I2C address to identify. I2C addresses of multiple devices may have the same address. The address is in the format of "0x20" (Example address). Steps to find out I2C address device is discussed in the following (step 4).
- The serial Clock (SCL) pin is to synchronize the transmitter and receiver.
- Serial Data (SDA) pin is to transfer data.
I2C LCD:
I2C LCD uses I2C communication interface to transfer the information required to display the content. I2C LCD requires only 2 lines (SDA and SCL) for transferring the data. So, the complexity of the circuit is reduced.
Interfacing I2C LCD to the Arduino:
I2C LCD can be connected to the Arduino directly with SDA pin to SDA pin and SCL pin to SCL pin as per the below circuit diagram. I2C LCD requires additional library to be installed. The next step is to connect the LCD to the address of the device using the following code. Those steps are explained in detail below.
Components required:
- Arduino Uno R3
- I2C LCD display
- Jumper Wires
Steps to interface LCD display with Arduino:
Step 1: Install the library for LCD display in Arduino IDE.
- Open Arduino IDE and navigate to Tools>Library Manager.
- Search for "LiquidCrystal I2C" and install the "LiquidCrystal I2C" library in the Arduino IDE.
Library Manager
Step 2: Import "LiquidCrystal_I2C.h" header file in the code.
- Define header file in the code " #include <LiquidCrystal_I2C.h> ".
Step 3: Connect display device to Arduino.
- Connect the SDA pin of an LCD display to the SDA pin of the Arduino.
- Connect the SCL pin of an LCD display to the SCL of the Arduino.
- Connect VCC to 5V pin
- Connect GND to GND pin.
LCD display interfacing circuit
Step 4: Find the I2C Address of the display device.
- Compile and run the below code to find the I2C Address.
- Before running this try step 5 using most commonly used addresses "0x27" or "0x3F". If those are not working, then continue with step 4.
Online simulation of I2C address finding using Tinkercad: https://www.tinkercad.com/things/0siOxvpmVNJ
Arduino code for I2C Address finding:
C++
// I2C address finding
#include <Wire.h>
void setup()
{
//Initializing wire
Wire.begin();
//Initializing seraial monitor at the baudrate of 9600
Serial.begin(9600);
}
void loop()
{
byte err, addr;
//Declaring variable to detect and count no. of I2C device found
int devices = 0;
// For loop to try multiple combinations of Address
for (addr = 1; addr < 127; addr++)
{
Wire.beginTransmission(addr);
err = Wire.endTransmission();
if (!err)
{
Serial.print("Address 0x");
if (addr < 16)
{
Serial.print("0");
}
Serial.println(addr, HEX);
devices++;
}
else if (err == 4)
{
Serial.print("Error at address 0x");
if (addr < 16)
{
Serial.print("0");
}
Serial.println(addr, HEX);
}
}
//Exception, when there is no I2C device found
if (!devices)
{
Serial.println("Please connect your I2C device");
}
//Waiting for 2 seconds
delay(2000);
}
Note: Make sure that you have connected the device properly.
Output:
I2C Address finding
Step 5: Define display device.
- Define the display device in the code as the following example code.
- Replace the address with your device address.
C++
#include <LiquidCrystal_I2C.h>
// Format => (ADDRESS,Width,Height )
LiquidCrystal_I2C lcd(0x20, 16, 2);
void setup()
{
// Initialize the lcd
lcd.init();
// Turn on the Backlight
lcd.backlight();
// ....
}
Step 6: Print characters in LCD.
- Here is the example code to display characters in LCD display.
Arduino code:
C++
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2); // Format -> (Address,Width,Height )
void setup()
{
// initialize the lcd
lcd.init();
// Turn on the Backlight
lcd.backlight();
}
void loop()
{
// Clear the display buffer
lcd.clear();
// Set cursor (Column, Row)
lcd.setCursor(0, 0);
// print "Hello" at (0, 0)
lcd.print("Hello");
// Set cursor (Column, Row)
lcd.setCursor(0,1);
// print "Geek" at (0, 1)
lcd.print("Geek");
delay(100);
}
Working of code:
Initially, the library, address, height and width are defined in the code.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20, 16, 2);
In the setup() function, initialization and backlight are enabled.
lcd.init();
lcd.backlight();
In the loop() function,
- Initially clearing the existing content in the display buffer.
lcd.clear();
- Cursor is set to (0,0) in the format of (row, column). whereas, indexing starts from 0.
// Set cursor (Column, Row)
lcd.setCursor(0, 0);
- print() function in the LCD is used to print the text where the cursor is set.
// print "Hello" at (0, 0)
lcd.print("Hello");
Output:
Printing characters using LCD display
Similar Reads
High Definition Multimedia Interface (HDMI) High Definition Multimedia Interface is one of the most used audio/video interfaces for transmitting uncompressed video data and compressed or uncompressed digital audio data from an HDMI-compliant source device. These devices can be a display controller, a compatible computer monitor, video project
4 min read
How to make digital voltmeter using Arduino? Digital VoltmeterVoltmeter is an instrument used to measure the potential difference or voltage (V) between two points of an electric circuit. Voltage is the potential difference between two points. It pushes charged electrons through conducting loop. It is also known as electric pressure, electromo
3 min read
Arduino Coding Basics In some previous articles, we have seen and understood the concepts of Arduino Boards, Arduino IDEs, and the installation procedure for Arduino software. Arduino IDE (Integrated Development Environment) is an essential which makes the task of uploading code on Arduino boards, an easy task. Instead o
14 min read
Difference between LED and LCD Light Emitting Diode (LED): LED is a type of LCD that actually accompanies the advancement of technology. This replaces the fluorescent tube with backlight technology, which produces a clearer picture than the LCD. LED have wider viewing angle than the LCD. It have better black level and contrast in
2 min read
Difference Between TN Panel and IPS Panel TN (Twisted Nematic) panels and IPS (In-Plane Switching) panels plays a pivotal role in determining the visual experience of the monitors and screens. Understanding the characteristics, advantages and disadvantages of these two panel types is essential for the making an informed decision when select
5 min read
Difference between Digital Light Processing (DLP) and Liquid Crystal Display (LCD) Projector 1. Digital Light Processing (DLP) Projector: Digital Light Processing (DLP) is a reflective projection method that combines a microelectrochemical system (MEMS) and projection display by the help of Digital Micrometer Device (DMD) microchip. The peculiar microchip is made by MEMS array of semiconduc
2 min read
Liquid Crystal Display Interfacing Pre-requisites: LCD Full Form LCD stands for Liquid Crystal Display. It is a flat panel display technology, mainly used in TVs and computer monitors, nowadays it is used for mobile phones also. In LCD, each pixel consists of a layer of molecules aligned between two transparent electrodes and two pol
4 min read
LCD Full Form What is the Full form of LCD?The full form of LCD is Liquid Crystal Display. it is a passive device, which means that it does not deliver any light to display characters, animations, videos, etc. LCD uses fluorescent tubes to lighten the picture, but canât provide a clearer picture as LED delivers.
9 min read
I2C Communication Protocol I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into devices for serial communication. It was originally designed by Philips Semiconductor in 1982. Recently, it is a widely used protocol for short-distance communication. It is also known as Two Wired I
6 min read
Functions of Video Controller in Raster Scan System Functions of Video Controller in Raster Scan System are explained following below. Deflection Voltage : In the output circuitry, it is video controller who generates horizontal and vertical deflection voltage with the help of which monitor can sweep its beam across screen during raster scan. The var
2 min read