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)    


<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="http://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
You need to install the library
<p>sohnyo yh i2c k code proteus py q ni compile hty??<br>dear why i2c program couldnt run on proteus bcz there became opcode error</p>
<p>Why is it so slow? </p><p>Nano updates display barely at 100-200Hz...</p>
<p>Is it possible to connect one of these I2C backpacks to an LCD Keypad shield?<br><br>I ask because i have one of these:</p><p><a href="https://www.foxytronics.com/products/324-lcd-shield-for-arduino" rel="nofollow">https://www.foxytronics.com/products/324-lcd-shiel...</a><br><br>And i also have a PCF8574T I2C module.<br><br>If i add this module, how would i maintain usage of the keys on the keypad? Is it as simple as running the A0 pin from the keypadshield to the A0 of the arduino?</p>
<p>hey i have 20*04 lcd. Is that lcd work with i2c controller?</p>
You need to buy a controller for your particular lcd in your case one that will run a 20x04 lcd. You can buy them online really cheap. And you can modify the code to work
I ordered a couple of lcd displays and a serial controller off of eBay. I've been reading some tutorials and i like yours. Great job!
<p>i get this error:</p><p>Arduino: 1.6.3 (Windows 8.1), Board: &quot;Arduino Uno&quot;</p><p>C:\Users\malthemail\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-67c63469f5ed\I2CIO.cpp:54:3: error: 'Wire' does not name a type</p><p> Wire.beginTransmission(DisplayI2CAddress);</p><p> ^</p><p>C:\Users\malthemail\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-67c63469f5ed\I2CIO.cpp:55:3: error: 'error' does not name a type</p><p> error = Wire.endTransmission();</p><p> ^</p><p>C:\Users\malthemail\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-67c63469f5ed\I2CIO.cpp:56:3: error: expected unqualified-id before 'if'</p><p> if (error==0){</p><p> ^</p><p>C:\Users\malthemail\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-67c63469f5ed\I2CIO.cpp:59:3: error: expected unqualified-id before 'else'</p><p> else //Some error occured</p><p> ^</p><p>C:\Users\malthemail\Documents\Arduino\libraries\fmalpartida-new-liquidcrystal-67c63469f5ed\I2CIO.cpp:63:1: error: expected declaration before '}' token</p><p> } </p><p> ^</p><p>Multiple libraries were found for &quot;Wire.h&quot;</p><p> Used: C:\Users\malthemail\Documents\Arduino\libraries\Wire</p><p> Not used: C:\Users\malthemail\Documents\Arduino\libraries\Robot_Control</p><p> Not used: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire</p><p>Error compiling.</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p>
<p>Its worth noting that there are two or three common pin mappings for the different I2C 1602 backpack boards out there. I just bought this one </p><p><a href="http://www.ebay.com/itm/Board-Module-Port-IIC-I2C-TWI-SPI-Serial-Interface-For-Arduino-1602-LCD-SU/201214652997" rel="nofollow">http://www.ebay.com/itm/Board-Module-Port-IIC-I2C-...</a></p><p>and the mapping is different than the MJKDZ board in this Instructable. Mine needs the following:</p><p>LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);</p><p>This site has a good explanation of the different style boards and several example sketches for Arduino.</p><p><a href="https://arduino-info.wikispaces.com/LCD-Blue-I2C" rel="nofollow">https://arduino-info.wikispaces.com/LCD-Blue-I2C</a></p><p>Note its possible with my variation of board to customize the address by bridging one or more of the A0, A1 &amp; A2 pads, so you could have multiple LCDs with I2C at different addresses. The default with all pads open is 0x27 and all pads bridged gives 0x20.</p><p>A hugh thanks to </p><p><a href="http://www.instructables.com/member/verdelj/" rel="nofollow"></a><a href="http://www.instructables.com/member/verdelj/" rel="nofollow">verdelj</a> for posting the I2C Scanner code, that was a BIG help in working out how to configure my board!</p>
<p>Hi Sir, what should I do if I'm using Arduino Nano?</p>
<p>the sketch is the same the only thing is the pins that you are going to use, on most arduino nano the SCL is pin A5 and for SCA pion A4 you have tho look at the version that you have and connect it to the apropiate pins.</p>
<p>can someone please help me to setup a 24&times;3 lcd on my raspberry pi b+</p><p>it has 18 pins link to photo here <a href="http://www.etypetv.com/pi" rel="nofollow">http://www.etypetv.com/pi</a></p><p>i need pin outs for this display to raspberry pi b+</p>
<p>a have mad all the steps,but dosen&acute;t work...it say &quot;no such file or directory&quot;</p>
Instala https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
<p>Arduino: 1.5.8 (Windows 7), Placa:&quot;Arduino Uno&quot;</p><p>lcd1602.ino:9:17: fatal error: LCD.h: No such file or directory</p><p>compilation terminated.</p><p>Erro ao compilar.</p><p> Este relat&oacute;rio teria mais informa&ccedil;&atilde;o com</p><p> &quot;Mostrar output verboso durante a compila&ccedil;&atilde;o&quot;</p><p> ativo em Ficheiro &gt; Prefer&ecirc;ncias</p>
You need to install the library on the link
<p>Excuse me, what about arduino uno, does programs it same?</p>
<p>the program is the same, all you have to do is connect SDA to pin A4 and SCL to pin A5 and it should work. on my is pin 20 and 21 because I am using arduino mega</p>
<p>Thank you for taking the time to put this together. I'm building a <a href="http://www.instructables.com/id/ARDUINO-SOLAR-CHARGE-CONTROLLER-Version-20/" rel="nofollow">solar battery charger controller</a> and the author <a href="http://www.instructables.com/id/ARDUINO-SOLAR-CHARGE-CONTROLLER-Version-20/" rel="nofollow">deba168</a> recommended your Instructable to help with the LCD display in the unit.</p>
<p>Why it shows that it does not find any devices? HELP!!! I inserted the scl AND the sda to the right position.I have the Arduino uno, but I changed the Serial.begin to 9600</p>
<p>first thing to check is make sure have sda is connected to A4 and scl to A5 pm the arduino uno. Also make sure you have the correct l2c address for the module, you might want to upload the i2c scanner sketch. To find the address for your module then just modify the sketch.</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>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>very useful! </p>
<p>Thanks for sharing this is valuable code. There are a lot of LCD's out there with little or no documentation. I have an Arduino Uno and the pin setup was SCL on A5 and the SDA on A4.</p>
The scanner works great it found the module address 0X20. Usually is 0x20 or 0x27 but the I2C Scanner its a great tool to have.

About This Instructable




Bio: Master Diesel Tech, in California. I love electronics and everything science .
More by verdelj:How to write a library the easy wayBootloading ATmega328 with Arduino Mega2560FM Radio the easy way
Add instructable to: