Arduino LCD with I2C Bus

Author : Dinesh Kumar Wickramasinghe

Introduction and Images

I was working with character LCD screens with Arduino and it was a headache for me to connect several connections and also an external potentiometer to control the brightness of the LCD. So I was looking for an easy way and then I found the I2C LCD Module.

This module make all our lives easy. You need only 4 connections from the LCD module to Arduino.

So, this tutorial is about connecting LCD to arduino with only 4 wires.

Before we begin, here are some images of my completed project.

I2C LCD Module
Arduino I2C Bus Module

The I2C LCD module helps us to connect character LCD screens by only using 4 wires. So you can save your Arduino ports. It also has a built in potentiometer which we can use to control the brightness of the LCD. It also has a jumper which we can use to turn on and off the LCD backlight. This module is based on the PCF8574A IC Chip.


Connect the Module to the LCD
Arduino I2C Bus Module Connect

The above image shows how I connected my LCD to the I2C Bus module. First I soldered a female header to my LCD display so that I can easily connect the I2C module to my LCD and later remove this module if I needed. Make sure you connect the module on correct direction.

Connection and Getting the Built in Address

These I2C bus modules has a built in address. So, the first step is to get this address. Once you done connecting the I2C module to your display, now you connect it to the Arduino using only 4 wires. Connections are as below.

I2C Module Pin Arduino Pin
GND Arduino GND
VCC Arduino +5V
SDA A4
SCL A5

One you done all the connection correctly, copy and paste the below source code to a new arduino file and upload it. You do not need any special libraries to run this.

#include <Wire.h>

void setup() {
  
  Serial.begin (9500);
  while (!Serial){}
  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  Wire.begin();
  
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);
      }
  }
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}

void loop() {}

                    

Open the Serial Monitor window to see the output. You will see an output similar to below screenshot. If you didn’t get any output, check the connections again.

Arduino I2C Module Address

The address marked in the red circle is the one we are looking for, copy and paste it (without brackets) to a notepad because we need it later.

Displaying Data on LCD

OK, Now you are ready to do the real experiment. The previous step was an additional step we have to do to get the address of your display module.

Now you need to install an additional library to display data on your LCD via the I2C bus. Download the I2C lcd library and add it to Arduino.

Now copy and paste the below source code to a new arduino project. Change the below line of code with the address value you received in the first experiment. For my module, I got the value 0x3F, then my code should be,

LiquidCrystal_I2C lcd(0x3F,20,2);
                    
Here is the source code

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,20,2);

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print("I2C LCD DEMO");
  lcd.setCursor(4,1);
  lcd.print("MANELSOFT");
}

void loop(){}
                    

Upload the code to Arduino. If you followed all the steps correctly, then you should get an output as on below image.

Arduino I2C Bus Module Working

Now you saw that how easy it is connect your LCD to Arduino. No headaches anymore. You can use this module with any experiments like temperature monitors etc.

Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : Jainish Prajapati
Added Date :9/6/2019 5:03:01 PM
Sir I need Similar Project With Ultrasonic sensor and buzzer with Display for Alarm System Can You Send Me??

 

Similar Projects

Go Top