Introduction: I2C LCD Controller (the Easy Way)

Picture of I2C LCD Controller (the Easy Way)

I am working on an alarm/weather station project and I wanted to use an LCD but dint want to have a lot of wires so I order a controller. This is just a very basic tutorial on how to hook it up, for the beginners like my self.

Step 1: Parts

Picture of Parts

Parts list:




1. LCD in this case a 16x02


1. I2C 1602 LCD Controller ($1.99 on ebay free shipping)


4. Jumper wires


1. Arduino ( I have a mega)    


Step 2: Soldering

Picture of Soldering

Now we solder the LCD and the controller. make sure you have the correct pin arrangement. Mine doesn't have a mark for pin one, but I just looked at the 5+ and GND inputs to figure it out.

Step 3: Connecting

Picture of Connecting

it is very simple to connect only 4 wire 5+ and GND and  SDA goes to Arduino pin 20 and SCL to pin 21 on my arduino mega. depending on what you have it might be different.

Step 4: The Code

Picture of The Code

Since the seller doesn't provide any info I neede to find the address for the module so I ran an I2C scanner
 //Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial)

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  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 (")");
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Step 5: The Code Part II

Picture of The Code Part II

the code is very simple..................................but you are going to need F Malpartida's   LCD LIB Once again very basic very simple.                                                                                                                                                                                                                            
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

#define I2C_ADDR    0x20  // Define I2C Address for controller
#define BACKLIGHT_PIN  7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() 
  lcd.begin (16,2);  // initialize the lcd
// Switch on the backlight

void loop()  

// Reset the display 
// Print on the LCD
  lcd.print("Hello, world!");


JunezRiyaz made it! (author)2017-11-30

markwills made it! (author)2016-07-06


If any of you are struggling, I have found that some LCD modules have a different pinout on the 16 way connector. I am using a 20x4 RT204-1 Version 3 LCD Module (blue characters with built in backlight).

After a considerable amount of head-scratching and looking at datasheets, I came up with the following, which DOES work on my Arduino UNO with the RT204-1 20x4 module. Note that the pin numbers in the #defines are different in my code from the code published in the article.

Some I2C LCD driver modules have definable addresses. Please see the attached photo. If your unit is like mine, it will have three pads, marked A0, A1, and A2. The idea is you can short out the links (using soldered on jumper wire, or even better, solder on some header pins and use links. The header pins just fit on the solder pads). It seems these address pins are tied HIGH (1) if they are not connected (so linking them will take them low (0)). Hence the address of my LCD module, with no links on the address pins is 0x27, as shown in the code below.

Maybe this will help.



#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
#define I2C_ADDR 0x27 // Define I2C Address for controller
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define BACKLIGHT 3

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()
lcd.begin (20,4); // initialize the lcd

// Switch on the backlight

void loop()
// Reset the display

// Print on the LCD
lcd.print("Hello Isla from Dad!");

zhollett (author)markwills2017-10-12

Thank You Mark!
I was scratching my head as well.

I have a 16x2 display on a Mega 2560 which seems to work on the same principal as your 20x4.
I had to change the "lcd.begin (20,4);" to "lcd.begin (16,2);"

bperrybap (author)markwills2017-05-08

The actual pinout of the LCD module is not different. What is different is how the PCF8574 8 pin output port is wired to the LCD pins. That is what the parameters in the constructor are configuring.

You could try using my hd44780 library instead.
It will automatically locate the i2c address and auto configure the pin mappings.

It can be quickly and easily installed using the IDE library manger and you can read more about it here:

seasider1960 (author)markwills2017-03-02

Thanks, very helpful!

Karanronin (author)markwills2016-12-25

Markwills, i have the same kind like yours although I am not able to display any text. Can u please help ASAP

Adjust the contrast pot on the back until you see text

omerfrydman (author)markwills2016-10-09


milky0071 (author)2017-09-28

Not Working out for me and my Arduino Pro Mini... HELP. Cannot find LCD Address

bkeskin (author)2017-09-21

Does it work with 1604 as well?

wimvanasperen (author)2017-09-12

why using port 0 thru 6, when using the I2C interface???

MassimoB3 (author)2017-08-29

Salve ma come devo fare se alla fine della scritta si accenda i led???? non ci riesco...

DennisK44 (author)2017-08-01

The code to search I2C address is awesome...Very Helpfull!

run7 (author)2017-04-04

were can you find the LCD.H Library

verdelj (author)run72017-04-06

You need to install this library

scratchndent (author)run72017-04-05

good question

sekara1 (author)2017-03-05

check this site

having lot of info on these I2C devices. I2C ADDRESS SCANNER is a cool one, you can find the address of your display with this

SteveA96 (author)2016-05-30

Two days and all I get is white boxes..
same on the Uno and Nano..
I am over it..

verdelj (author)SteveA962016-05-30

We need more info what controller and what lcd are you using. It sounds to me like your backlight is out of adjustment.

SteveA96 (author)verdelj2016-05-31

The DF Robot display works fine (only tested on the Nano) with a certain program but the other thing doesn't work at all on both my Nano or Uno, just a blue led backlight and white boxes.

Damola_ (author)SteveA962017-03-03

How did you solve this?

teddlesruss (author)SteveA962016-07-06

I found that the white boxes were a result of the contrast control being set wrong, once I figured that out it worked for me.

mrsyfy (author)SteveA962016-06-27

send me your code and I will take a look at it for you. I am working on a four line display using the I2C and have been sending text to easy.

AJRSousa (author)2017-01-17

Really thanks!! The address are diferent!! 27 and 3F

Great help!!

Karanronin (author)2016-12-25

Guys no text, only light is present. Any suggesstions

Ralphxyz (author)2016-12-05


I finally got it working thanks to your help!!

markwills, it was your code that finally worked.

Now what /why are the pins defined?

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

#define BACKLIGHT 3

How would they be used?

Thanks again,


matti.virta.1 (author)2016-11-14

i come alltime i try test "Hello wordl" text same, proplem lcd show only "H" letter not more and second row have "heart" not more. what have wrong at library ?

diy_bloke (author)2014-06-17

i understand that the backlight polarity can be combined in the lcd initialisation:

lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, POSITIVE);

natong (author)diy_bloke2016-08-18

lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN, POSITIVE);

diy_bloke (author)natong2016-08-18

yes you are fully right. tnx

verdelj (author)diy_bloke2014-06-17

Yes you are correct, its all about the efficiency of the code the way you have it it is much better and the way is suppose to be done. but for the lack of time and knowledge I used a different method. Thank you for pointing it out, if it wasn't for you I would have never given a second thought and looked at that library again. Thanks

ExplosionGaming (author)2016-07-14

For some reason it uploads but nothing happens and it says;

Multiple libraries were found for "LCD.h"
Used: C:\Users\-\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-bb6d545c00c3
Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal
Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal
Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal
Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal

ExplosionGaming (author)2016-07-14

do we need both parts of the code?

JackSoldano made it! (author)2016-05-27

Really helpful guide for a project I'm testing at the moment, Thanks!

SyamsullH made it! (author)2016-05-20

need help...
when scanning the serial addres i2c

verdelj (author)SyamsullH2016-05-20

Just change you baud rate onn the serial monitor to 115200 you have it as 9600

verdelj (author)SyamsullH2016-05-20

Your baud rate is wrong should
Serial.begin (115200);

jessey (author)2016-05-05

OK not so simple for me. What do I do with the code in step 4? Obviously I run the code in step 5 but where do I get the download F Malpartida's LCD LIB that you make reference to in step 5? Have a look in the URL you provided that says has the file we need, there is no such file there. Whats the name of the zip file I'm suppose to download it's definitely not LCD LIB?

Please advise me...


verdelj (author)jessey2016-05-06

depending on the version of the IDE that you are running. if you have the newest version you can use the library manager to install the library.....Open the IDE and click to the "Sketch" menu and then IncludeLibrary > Manage Libraries. if you are using an older version all you have to do is unzip the files and copy the folder to you library folder.....

verdelj (author)jessey2016-05-06

you can download it form the top link.

jessey (author)2016-05-05

You know,

Anyone that's reading this can answer my question below or the one VasaS asked over a year ago. It looks like the guy that posted this just gave up answering questions or just doesn't bother coming around anymore. So if anyone reads this and if you know the answers then by all means jump in to answer.



VasaS (author)2015-02-04

How did you find the pin values bellow?

#define En_pin 4
#define Rw_pin 5
#define Rs_pin 6
#define D4_pin 0
#define D5_pin 1
#define D6_pin 2
#define D7_pin 3

Are they the pin numbers on the actual controller that are plugged into the lcd?

If they are how did you find those values?

egagnon1 (author)VasaS2016-05-01

It's the pinout value of the i2c device connected to the screen.

verdelj (author)VasaS2015-02-06

yes, I am using an lcd with a Hitachi HD44780 driver if you look at the picture with the pinout you will see the values.

NikolaR6 (author)2016-01-16

Well, it is working! Pay attention on contrast adjusting on the back of the I2C... I thought that LCD is not working because I didn't see any chars. :D

ephestione (author)NikolaR62016-04-04


I lost some minutes believing I had some strange display or controller or that one or both of them were defective, but as soon as I adjusted the contrast the darn thing worked like a charm as per turbiny code.

I thought that potentiometer was for backlight at first so I didn't really give it much attention.

turbiny (author)2015-08-12

just posting maybe someone will need this
i ordered from aliexpress and this is the code the worked after a week of trying:
i did altered some comments

/* Example Software Sketch

20 character 4 line I2C Display

Backpack Interface labelled "LCM1602 IIC A0 A1 A2" */

/*-----( Import needed libraries )-----*/

#include <Wire.h> // Comes with Arduino IDE

// Get the LCD I2C Library here:


// Move any other LCD libraries to another folder or delete them

// See Library "Docs" folder for possible commands etc.

#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/


/*-----( Declare objects )-----*/

// set the LCD address to LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); for a 16 chars 2 line display

// Set the pins on the I2C chip used for LCD connections:

// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

/*-----( Declare Variables )-----*/


void setup() /*----( SETUP: RUNS ONCE )----*/


Serial.begin(9600); // Used to type in characters

lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines and turn on backlight

// ------- Quick 3 blinks of backlight -------------

for(int i = 0; i< 3; i++)







lcd.backlight(); // finish with backlight on

//-------- Write characters on the display ----------------

// NOTE: Cursor Position: CHAR, LINE) start at 0

lcd.setCursor(2,0); //Start at character 4 on line 0

lcd.print("hello BEBUSH!");



lcd.print("WE <3 YOU");



lcd.print("16by2 Line Display");





// Wait and then tell user they can start the Serial Monitor and type in characters to

// Display. (Set Serial Monitor option to "No Line Ending")

lcd.setCursor(0,0); //Start at character 0 on line 0

lcd.print("Start Serial Monitor");


lcd.print("Type chars 2 display");

}/*--(end setup )---*/

void loop() /*----( LOOP: RUNS CONSTANTLY )----*/



// when characters arrive over the serial port...

if (Serial.available()) {

// wait a bit for the entire message to arrive


// clear the screen


// read all the available characters

while (Serial.available() > 0) {

// display each character to the LCD





}/* --(end main loop )-- */

/* ( THE END ) */

xallie (author)turbiny2016-02-20

Get some compilation error saying "POSITIVE" was not declated in this scope =/

NikolaR6 (author)turbiny2016-01-16

I founded address of my I2C and I used your code but all I god was 3 blinks and than only empty backlited display...

YaronR1 (author)turbiny2016-01-02

Thank you, your code works! Saved me a week I guess :)

About This Instructable




Bio: Master Diesel Tech, in California. I love electronics and everything science .
More by verdelj:LED Video Array (the Easy Way)How to write a library the easy wayBootloading ATmega328 with Arduino Mega2560
Add instructable to: