{"id":173,"date":"2015-11-18T01:12:35","date_gmt":"2015-11-18T01:12:35","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=173"},"modified":"2020-10-12T16:37:07","modified_gmt":"2020-10-12T16:37:07","slug":"how-to-set-up-and-use-a-1602-i2c-serial-lcd-with-your-arduino","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=173","title":{"rendered":"How to set up and use a 1602 I2C serial LCD with your ARDUINO."},"content":{"rendered":"<p>This tutorial will show you How to set up and use a 1602 I2C serial LCD with your ARDUINO.\u00a0, In this tutorial I will be using a ARDUINO UNO but the connections will be similar for all ARDUINO boards.<\/p>\n<h2>\u00a0 The video below shows the LCD in action!<\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/youtu.be\/8e-F5f9kogU\">https:\/\/youtu.be\/8e-F5f9kogU<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_174\" style=\"width: 828px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-174\" class=\"wp-image-174\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd.jpg?w=300\" alt=\"i2clcd\" width=\"818\" height=\"545\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd.jpg 5184w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd-300x200.jpg 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd-768x512.jpg 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/i2clcd-1024x683.jpg 1024w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/a><p id=\"caption-attachment-174\" class=\"wp-caption-text\">How to set up and use a 1602 I2C serial LCD with your ARDUINO.<\/p><\/div>\n<p>Connecting the I2C lcd to your ARDUINO is simple.\u00a0 First\u00a0\u00a0connect the VCC &amp; ground\u00a0from the LCD&#8217;s I2C pins to\u00a0the power and ground pins\u00a0of your ARDUINO board,\u00a0Next connect the SCL pin to pin A5 on your ARDUINO board and the SDA pin of your I2C LCD to pin A4 on your ARDUINO board.<\/p>\n<p>&nbsp;<\/p>\n<h3>Parts List.<\/h3>\n<p>#affiliate links#<\/p>\n<ol>\n<li><a href=\"http:\/\/www.dx.com\/s\/arduino?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO board<\/a><\/li>\n<li><a href=\"http:\/\/www.dx.com\/s\/Potentiometer?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">Potentiometer <\/a><\/li>\n<li><a href=\"http:\/\/www.dx.com\/p\/i2c-iic-lcd-1602-display-module-with-white-backlight-4-pin-cable-for-arduino-raspberry-pi-374741?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">1602 I2C 16 X 2 LCD screen<\/a><\/li>\n<li><a href=\"http:\/\/www.dx.com\/s\/Bread board?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">Bread board<\/a><\/li>\n<li><a href=\"http:\/\/www.dx.com\/s\/jumper wires?Utm_rid=99156049&amp;Utm_source=affiliate\" target=\"_blank\" rel=\"noopener noreferrer\">jumper wires <\/a><\/li>\n<\/ol>\n<p>For the demonstration of how to use the I2C LCD we are going to connect a potentiometer to the ARDUINO and display the value on the LCD display, Connect the middle pin of the pot to analog pin A0 on your ARDUINO and the other two pins to ground and power..<\/p>\n<p>If you know the address of your 1602 serial I2C LCD you can skip the next step!!<\/p>\n<p>&nbsp;<\/p>\n<h2>Detecting your I2C address.<\/h2>\n<p>If you don&#8217;t know the LCD&#8217;s I2C address just copy and past the following code into your ARDUINO IDE &amp; upload it to your board, Open your serial monitor and write down the address that is displayed on the monitor.\u00a0 This code and more info about it can be found at: <a href=\"http:\/\/playground.arduino.cc\/Main\/I2cScanner\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/playground.arduino.cc\/Main\/I2cScanner<\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"de1\"><span class=\"co2\">#include &lt;Wire.h&gt;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\"><span class=\"kw4\">void<\/span> setup<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\"><span class=\"br0\">{<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 Wire.<span class=\"me1\">begin<\/span><span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 Serial.<span class=\"me1\">begin<\/span><span class=\"br0\">(<\/span><span class=\"nu0\">9600<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;<span class=\"es1\">\\n<\/span>I2C Scanner&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\"><span class=\"br0\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\"><span class=\"kw4\">void<\/span> loop<span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\"><span class=\"br0\">{<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 byte error<span class=\"sy0\">,<\/span> address<span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"kw4\">int<\/span> nDevices<span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;Scanning&#8230;&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 nDevices <span class=\"sy0\">=<\/span> <span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"kw1\">for<\/span><span class=\"br0\">(<\/span>address <span class=\"sy0\">=<\/span> <span class=\"nu0\">1<\/span><span class=\"sy0\">;<\/span> address <span class=\"sy0\">&lt;<\/span> <span class=\"nu0\">127<\/span><span class=\"sy0\">;<\/span> address<span class=\"sy0\">++<\/span> <span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"br0\">{<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 \u00a0 <span class=\"co1\">\/\/ The i2c_scanner uses the return value of<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"co1\">\/\/ the Write.endTransmisstion to see if<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"co1\">\/\/ a device did acknowledge to the address.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 Wire.<span class=\"me1\">beginTransmission<\/span><span class=\"br0\">(<\/span>address<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 error <span class=\"sy0\">=<\/span> Wire.<span class=\"me1\">endTransmission<\/span><span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>error <span class=\"sy0\">==<\/span> <span class=\"nu0\">0<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"br0\">{<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">print<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;I2C device found at address 0x&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>address<span class=\"sy0\">&lt;<\/span><span class=\"nu0\">16<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 \u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">print<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;0&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">print<\/span><span class=\"br0\">(<\/span>address<span class=\"sy0\">,<\/span>HEX<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8221; \u00a0!&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 nDevices<span class=\"sy0\">++;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 \u00a0 <span class=\"br0\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"kw1\">else<\/span> <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>error<span class=\"sy0\">==<\/span><span class=\"nu0\">4<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"br0\">{<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">print<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;Unknow error at address 0x&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>address<span class=\"sy0\">&lt;<\/span><span class=\"nu0\">16<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 \u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">print<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;0&#8221;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 \u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span>address<span class=\"sy0\">,<\/span>HEX<span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 <span class=\"br0\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"br0\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"kw1\">if<\/span> <span class=\"br0\">(<\/span>nDevices <span class=\"sy0\">==<\/span> <span class=\"nu0\">0<\/span><span class=\"br0\">)<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\">\u00a0 \u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;No I2C devices found<span class=\"es1\">\\n<\/span>&#8220;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 <span class=\"kw1\">else<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 \u00a0 Serial.<span class=\"me1\">println<\/span><span class=\"br0\">(<\/span><span class=\"st0\">&#8220;done<span class=\"es1\">\\n<\/span>&#8220;<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de1\">\u00a0 delay<span class=\"br0\">(<\/span><span class=\"nu0\">5000<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">;<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"co1\">\/\/ wait 5 seconds for next scan<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"de2\"><span class=\"br0\">}<\/span><\/div>\n<div class=\"de2\"><\/div>\n<h2 class=\"de2\">\u00a0 Time to play with the LCD!!<\/h2>\n<p>You will need to download and install the following library for your I2C serial LCD to work :\u00a0 <a href=\"https:\/\/bitbucket.org\/fmalpartida\/new-liquidcrystal\/downloads\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/bitbucket.org\/fmalpartida\/new-liquidcrystal\/downloads<\/a>&#8230; Download the 1.3.4 version!<\/p>\n<div class=\"de2\">\u00a0 Now that you have your I2C address you can copy and past the following code into your IDE to have some fun with your LCD screen.\u00a0First look at the picture before the\u00a0code and change the value that is circled in the\u00a0code to your I2C address, Then upload\u00a0it to your ARDUINO.<\/div>\n<div class=\"de2\">\u00a0\u00a0Once the code is uploaded to your arduino just turn the potentiometer and the value will be displayed on your LCD screen.<\/div>\n<div id=\"attachment_176\" style=\"width: 826px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/lcd_pot-arduino-1-6.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-176\" class=\"wp-image-176\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/lcd_pot-arduino-1-6.jpg?w=226\" alt=\"lcd_pot Arduino 1.6\" width=\"816\" height=\"1083\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/lcd_pot-arduino-1-6.jpg 500w, https:\/\/thezhut.com\/wp-content\/uploads\/2015\/11\/lcd_pot-arduino-1-6-226x300.jpg 226w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><\/a><p id=\"caption-attachment-176\" class=\"wp-caption-text\">How to set up and use a 1602 I2C serial LCD with your ARDUINO.<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>#include &lt;Wire.h&gt;<br \/>\n#include &lt;LiquidCrystal_I2C.h&gt;<br \/>\n\/\/ Set the LCD I2C address<br \/>\nLiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);<br \/>\nvoid setup()<br \/>\n{<br \/>\nlcd.begin(16, 2);\u00a0 \/\/ initialize the lcd<br \/>\nlcd.clear();<\/p>\n<p>}<br \/>\nvoid loop()<br \/>\n{<br \/>\nint val = (analogRead(A0)); \/\/read analog pin A0<br \/>\nlcd.setCursor(5, 0);<br \/>\nlcd.print(&#8220;VALUE=&#8221;);<br \/>\nlcd.setCursor(6, 1);<br \/>\nlcd.print(val);<br \/>\ndelay(500);<br \/>\nlcd.clear();<br \/>\n}<\/p>\n<p>If you have any questions or comments please post them on our <a href=\"https:\/\/www.facebook.com\/zarduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Facebook page.<\/a><\/p>\n<p>Also if your looking for some more ARDUINO projects or info check out our <a href=\"https:\/\/zhutarduino.wordpress.com\/arduino-projects\/\" target=\"_blank\" rel=\"noopener noreferrer\">projects page.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>How to set up and use a 1602 I2C serial LCD with your ARDUINO.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will show you How to set up and use a 1602 I2C serial LCD with your ARDUINO.\u00a0, In this tutorial I will be using a ARDUINO UNO but the connections will be similar for all ARDUINO boards. \u00a0 &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=173\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":10,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-173","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":1,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/173\/revisions"}],"predecessor-version":[{"id":1606,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/173\/revisions\/1606"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/10"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}