Arduino

How to interface LCD with Arduino using I2C module

The LCD can be interfaced with Arduino Uno using the I2C which will utilize fewer Arduino digital I/O pins. We know that if we interface LCD with Arduino by connecting 4 data lines, it needs at least six digital I/O pins for a successful connection. The I2C uses serial communication using the SDA and SCL terminals of Arduino and transfers the data on an LCD.

In this write-up, the I2C is explained, and also the method by which it is used with LCD to interface it with Arduino is explained.

What is an I2C

The I2C is a serial communication protocol, it has two terminals, one is of the clock and the other is for serial data communication. This device is an example of the serial protocol and can be used with other electronic devices to communicate through serial communication.

The I2C has the SDA and SCL terminals, the SCL is the clock line that transfers data depending on its High and Low states whereas the SDA is a data line, which contains the data to be sent or received to any device according to the states of a clock.

The other two terminals are of Vcc and the ground which is used to complete the circuit of the I2C and on the other side of the board, there are pins known as LED, which are connected to the potentiometer (embedded on the board) which can vary the resistance of the I2C circuit. We can also use these terminals to control the resistance of the circuit of I2C by some other methods like using an LDR or transistor.

How to interface the LCD with Arduino using an I2C Module

We can use an I2C module with an LCD to interface it with Arduino to display the output of Arduino on the LCD screen. The different Arduino boards have different pins of SCL and SDA so it’s better to read the datasheet of the board. We are using Arduino Uno, which has the A4 pin for SDA and A5 pin for SCL, so by connecting these pins with the pins of I2C, we can start the I2C communication with LCD. Besides this, in the sketch of Arduino IDE, we have to include the library of “LiquidCrystal_I2C.h” to use the I2C with LCD.

What is an Arduino code for LCD interfacing with the I2C module

We will write a simple Arduino code for the I2C LCD interfacing it with Arduino and will print “LinuxHint” on the LCD screen of LCD. The code for this purpose will be:

#include <LiquidCrystal_I2C.h>
//included the library of I2C LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
//declared the I2C LCD

void setup(){
lcd.init();
//used the built-in function of keypad library function to initialize the LCD
lcd.backlight();
//turn on the backlight of LCD
lcd.print("LinuxHint");
// print on the LCD
}
void loop(){
}

Explanation of code: In the above code, we simply include the library of “LiquidCrystal_I2C.h” and initialize the LCD with the I2C. Then we used the functions of init() to initialize the LCD, backlight() to turn on the backlight of the LCD, and print() to display the “LinuxHint”.

Schematics and Hardware

For the output of the above code, the circuit needs the following components:

  • Arduino Uno
  • Breadboard
  • Connecting wires
  • I2C Bus

The circuit diagram will be:

In the above circuit diagram, the I2C is connected with the pins of the LCD, moreover, we have connected the ground pin of I2C with the ground of Arduino, the VCC pin of I2C is connected with 5 volts of Arduino, the SDA pin of I2C is connected with A4, and the SCL pin of I2C is connected with the A5 pin of Arduino.

The Hardware configuration of the above circuit is:

In the above circuit, the I2C module is connected parallel to the pins of the LCD (you can also solder the LCD with I2C permanently) and the pins of GND, VCC, SDA, and SCL are connected with the ground, 5 volts, A4, and A5 pins of Arduino respectively.

Conclusion

The LCD can be easily interfaced with Arduino using the I2C and it has only 4 connections, so you have to just connect the I2C with the pins of LCD and SCL, SDA pins with the Arduino. There is no need to use the digital pins of Arduino which can be utilized for any other purposes. In this write-up, the method of interfacing the LCD with Arduino using the I2C has been explained which uses the I2C communication to send data from Arduino to the LCD.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.