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

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

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

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

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

the code is very simple..................................but you are going to need F Malpartida's   LCD LIB https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads 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!");

<p>Guys,</p><p>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).</p><p>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. </p><p>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.</p><p>Maybe this will help.</p><p>Regards</p><p>Mark</p><p>#include &lt;Wire.h&gt;<br>#include &lt;LCD.h&gt;<br>#include &lt;LiquidCrystal_I2C.h&gt; // F Malpartida's NewLiquidCrystal library<br>#define I2C_ADDR 0x27 // Define I2C Address for controller<br>#define En_pin 2<br>#define Rw_pin 1<br>#define Rs_pin 0<br>#define D4_pin 4<br>#define D5_pin 5<br>#define D6_pin 6<br>#define D7_pin 7<br>#define BACKLIGHT 3</p><p>LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);</p><p>void setup()<br>{<br>lcd.begin (20,4); // initialize the lcd</p><p>// Switch on the backlight<br>lcd.setBacklightPin(BACKLIGHT,POSITIVE);<br>lcd.setBacklight(HIGH);<br>}</p><p>void loop()<br>{<br>// Reset the display<br>lcd.clear();<br>delay(1000);<br>lcd.home();</p><p>// Print on the LCD<br>lcd.backlight();<br>lcd.setCursor(0,0);<br>lcd.print(&quot;Hello Isla from Dad!&quot;);<br>delay(1000);<br>}</p>
<p>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.</p><p>You could try using my hd44780 library instead.<br>It will automatically locate the i2c address and auto configure the pin mappings.</p><p>It can be quickly and easily installed using the IDE library manger and you can read more about it here: </p><p>https://github.com/duinoWitchery/hd44780</p>
<p>Thanks, very helpful!</p>
<p>Markwills, i have the same kind like yours although I am not able to display any text. Can u please help ASAP</p>
<p>Adjust the contrast pot on the back until you see text</p>
<p>were can you find the LCD.H Library</p>
You need to install this library<br>https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
<p>good question</p>
<p>check this site <a href="https://arduino-info.wikispaces.com/LCD-Blue-I2C?responseToken=be231d479e36e5aa41ce1f15b7fbda0a" rel="nofollow">https://arduino-info.wikispaces.com/LCD-Blue-I2C?r...</a></p><p>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</p>
<p>Two days and all I get is white boxes.. <br>same on the Uno and Nano.. <br>I am over it..</p>
We need more info what controller and what lcd are you using. It sounds to me like your backlight is out of adjustment.
<p>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.<br></p>
<p>How did you solve this?</p>
<p>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.</p>
<p>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. </p>
<p>Really thanks!! The address are diferent!! 27 and 3F</p><p>Great help!!</p>
<p>Guys no text, only light is present. Any suggesstions</p>
<p>First thing THANKS EVERYONE FOR YOUR CONTRIBUTIONS!!</p><p>I finally got it working thanks to your help!!</p><p>markwills, it was your code that finally worked.</p><p>Now what /why are the pins defined?</p><p>#define En_pin 2</p><p>#define Rw_pin 1</p><p>#define Rs_pin 0</p><p>#define D4_pin 4</p><p>#define D5_pin 5</p><p>#define D6_pin 6</p><p>#define D7_pin 7</p><p>#define BACKLIGHT 3</p><p>How would they be used?</p><p>Thanks again,</p><p>Ralph</p>
<p>i come alltime i try test &quot;Hello wordl&quot; text same, proplem lcd show only &quot;H&quot; letter not more and second row have &quot;heart&quot; not more. what have wrong at library ?</p>
<p>i understand that the backlight polarity can be combined in the lcd initialisation:</p><p>lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, POSITIVE);</p>
<p>lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN, POSITIVE);</p>
<p>yes you are fully right. tnx</p>
<p>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</p>
<p>For some reason it uploads but nothing happens and it says;</p><p>Multiple libraries were found for &quot;LCD.h&quot;<br> Used: C:\Users\-\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-bb6d545c00c3<br> Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal<br> Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal<br> Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal<br> Not used: C:\Users\-\Documents\Arduino\libraries\NewliquidCrystal</p>
<p>do we need both parts of the code?</p>
<p>Really helpful guide for a project I'm testing at the moment, Thanks!</p>
<p>need help...<br>when scanning the serial addres i2c</p>
Just change you baud rate onn the serial monitor to 115200 you have it as 9600
Your baud rate is wrong should <br>Serial.begin (115200);
<p>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?</p><p>Please advise me...</p><p>Thanks</p>
<p>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 &quot;Sketch&quot; menu and then Include<b>Library</b> &gt; Manage <b>Libraries</b>. if you are using an older version all you have to do is unzip the files and copy the folder to you library folder.....</p><p>https://www.arduino.cc/en/Guide/Libraries</p>
<p>https://bitbucket.org/fmalpartida/</p><p><a href="https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads" rel="nofollow">https://bitbucket.org/fmalpartida/new-liquidcrysta...</a></p><p> you can download it form the top link.</p>
<p>You know,</p><p>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.</p><p>Thanks</p><p>jes</p>
<p>How did you find the pin values bellow?</p><p>#define BACKLIGHT_PIN 7<br> #define En_pin 4<br> #define Rw_pin 5<br> #define Rs_pin 6<br> #define D4_pin 0<br> #define D5_pin 1<br> #define D6_pin 2<br> #define D7_pin 3</p><p>Are they the pin numbers on the actual controller that are plugged into the lcd?</p><p>If they are how did you find those values?</p>
It's the pinout value of the i2c device connected to the screen.
<p>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.</p>
<p>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</p>
<p>THIS.</p><p>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.</p><p>I thought that potentiometer was for backlight at first so I didn't really give it much attention.</p>
<p>just posting maybe someone will need this<br>i ordered from aliexpress and this is the code the worked after a week of trying:<br>i did altered some comments <br><br>/* YourDuino.com Example Software Sketch</p><p> 20 character 4 line I2C Display</p><p> Backpack Interface labelled &quot;LCM1602 IIC A0 A1 A2&quot;</p><p> terry@yourduino.com */</p><p>/*-----( Import needed libraries )-----*/</p><p>#include &lt;Wire.h&gt; // Comes with Arduino IDE</p><p>// Get the LCD I2C Library here: </p><p>// <a href="https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads" rel="nofollow"> https://bitbucket.org/fmalpartida/new-liquidcryst...</a></p><p>// Move any other LCD libraries to another folder or delete them</p><p>// See Library &quot;Docs&quot; folder for possible commands etc.</p><p>#include &lt;LiquidCrystal_I2C.h&gt;</p><p>/*-----( Declare Constants )-----*/</p><p>//none</p><p>/*-----( Declare objects )-----*/</p><p>// 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</p><p>// Set the pins on the I2C chip used for LCD connections:</p><p>// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol</p><p>LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address</p><p>/*-----( Declare Variables )-----*/</p><p>//none</p><p>void setup() /*----( SETUP: RUNS ONCE )----*/</p><p>{</p><p> Serial.begin(9600); // Used to type in characters</p><p> lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines and turn on backlight</p><p>// ------- Quick 3 blinks of backlight -------------</p><p> for(int i = 0; i&lt; 3; i++)</p><p> {</p><p> lcd.backlight();</p><p> delay(250);</p><p> lcd.noBacklight();</p><p> delay(250);</p><p> }</p><p> lcd.backlight(); // finish with backlight on </p><p>//-------- Write characters on the display ----------------</p><p>// NOTE: Cursor Position: CHAR, LINE) start at 0 </p><p> lcd.setCursor(2,0); //Start at character 4 on line 0</p><p> lcd.print(&quot;hello BEBUSH!&quot;);</p><p> delay(1000);</p><p> lcd.setCursor(2,1);</p><p> lcd.print(&quot;WE &lt;3 YOU&quot;);</p><p> delay(1000); </p><p> lcd.setCursor(0,2);</p><p> lcd.print(&quot;16by2 Line Display&quot;);</p><p> lcd.setCursor(0,2);</p><p> delay(2000); </p><p> lcd.print(&quot;http://YourDuino.com&quot;);</p><p> delay(8000);</p><p>// Wait and then tell user they can start the Serial Monitor and type in characters to</p><p>// Display. (Set Serial Monitor option to &quot;No Line Ending&quot;)</p><p> lcd.setCursor(0,0); //Start at character 0 on line 0</p><p> lcd.print(&quot;Start Serial Monitor&quot;);</p><p> lcd.setCursor(0,1);</p><p> lcd.print(&quot;Type chars 2 display&quot;); </p><p>}/*--(end setup )---*/</p><p>void loop() /*----( LOOP: RUNS CONSTANTLY )----*/</p><p>{</p><p> {</p><p> // when characters arrive over the serial port...</p><p> if (Serial.available()) {</p><p> // wait a bit for the entire message to arrive</p><p> delay(100);</p><p> // clear the screen</p><p> lcd.clear();</p><p> // read all the available characters</p><p> while (Serial.available() &gt; 0) {</p><p> // display each character to the LCD</p><p> lcd.write(Serial.read());</p><p> }</p><p> }</p><p> }</p><p>}/* --(end main loop )-- */</p><p>/* ( THE END ) */</p>
<p>Get some compilation error saying &quot;POSITIVE&quot; was not declated in this scope =/</p>
<p>I founded address of my I2C and I used your code but all I god was 3 blinks and than only empty backlited display...</p>
<p>Thank you, your code works! Saved me a week I guess :)</p>
Glad i was helpful<br>I had to search many sites/forums until i found what worked
<p>I have a 16X2 I2C LCD from Banggood, which I have been trying to get to work for a week now. I've tried several tutorials, suggestion etc. Most errored during the compile, and one actually uploaded, but then just blinked the backlight dimly.</p><p>The sketch you posted here is the first to actually work, after I changed the address to this board's 0x3f!</p><p>Now, I can use your sketch to learn and expand. I will be trying to make the serial input scroll to line 2.</p><p>Thank you,</p><p>Howard</p>
<p>I'm new to arduino and i just want to ask why do you still have to define pin 0-7 for En, Rw, Rs, D4,.... </p>
<p>Nice tutorial. Code from the scratch didn't work for Arduino UNO.</p>
<p>I used code writen by <a href="https://www.instructables.com/member/turbiny" rel="nofollow">turbiny</a> and all I got is 3 blinks. :)</p>
<p>My I2C address was 0x3F, and I appeared to have no problems but this: LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); gave me the error that the integer provided by I2C_ADDR was not a valid argument, the first argument being 'int'. I don't know what to do.</p>
You need to install the library https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

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 way Bootloading ATmega328 with Arduino Mega2560 
Add instructable to: