I2C Arduino Code for LCD Displays & Adaptor Modules

Click Here to watch our YouTube Video for a full description
To use an I2C ready LCD Display or I2C Backpack Adaptor Module with Arduino you will need the Wire Library and the NewLiquidCrystal Library.  Wire is already included in the Arduino IDE but you will need to download NewLiquidCrystal - click here to download:
NewLiquidCrystal

Once you've loaded that into your Arduino setup, you can start a sketch to use an I2C LCD.

Here is an example sketch to display two lines of text.
The complete code is at the bottom of the page, but first here is some explanation:

You then need to create a Display 'Object' you can communicate with, like this:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

You can then send commands or information to the screen using lcd (or any other name that you have chosen for your display) followed by a point and then a command, finishing with empty brackets and a semicolon

For example: lcd.clear();

In the setup you need to add these commands:

void setup() {

  lcd.begin(16,02);   //make this (20,04) for the larger screens

  lcd.clear();

  lcd.setBacklight(HIGH);

}

and then in the loop you can get the Display to show your information or text:

void loop() {

  lcd.setCursor(0, 0);  //Character 1 on the first line

  lcd.print("LCD Screen");

  lcd.setCursor(0, 1);  //Character 1 on the second line

  lcd.print("Easy to set up");

   delay(2000);

}

Whole code to copy and paste:

/*WWW.Q26.CO.UKConnect a 1602 or 2004 LCD Display using I2C

Display simple text on 2 lines

See our website and YouTube videos for more detailed information*/

//NewLiquidCrystal Libray from Francisco Malpartida - check our website for link

//Connect 5v/Gnd and data lines - SDA to A4 and SCL to A5

//libraries needed for this sketch:

#include    LiquidCrystal_I2C.h    //put this name inside '<>'

#include    Wire.h   //put this name inside '<>'

//LCD Display initialise:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //Check address using I2C Scanner and change if necessary

void setup() {

  lcd.begin(16,02);   //change this to (20,04) for the larger screens

  lcd.clear();

  lcd.setBacklight(HIGH);

}

void loop() {

  lcd.setCursor(0, 0);  //Character 1 on the first line

  lcd.print("LCD Screen");

  lcd.setCursor(0, 1);  //Character 1 on the second line

  lcd.print("Easy to set up");

   delay(2000);

}

//Error Message? Have you put the library names inside the 'less than' and 'more than' brackets '<>'?