{"id":2973,"date":"2014-05-12T20:29:05","date_gmt":"2014-05-12T20:29:05","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=2973"},"modified":"2019-04-02T10:23:37","modified_gmt":"2019-04-02T10:23:37","slug":"arduino-display-the-led-brightness-on-a-lcd-16x2","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-display-the-led-brightness-on-a-lcd-16x2\/","title":{"rendered":"Arduino &#8211; Display the LED Brightness on a LCD 16&#215;2"},"content":{"rendered":"<p>In this project we&#8217;re going to display the LED brightness on a LCD 16&#215;2 with a progress bar. This is a good Arduino beginner project for getting started with the LCD display. We provide a list of the parts required, schematic diagram, and code.<br \/>\n<!--more--><\/p>\n<h2>Watch the video demonstration below<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/sAklcqiywPw?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>Introducing the LCD<\/h2>\n<p>The simplest and inexpensive way to display information is with an LCD (liquid crystal display). These are found in everyday electronics devices such as vending machines, calculators, parking meters, printers, and so on, and are ideal for displaying text or small icons. The figure below shows a 16\u00d72 LCD front and the back view.<\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-54550\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd.jpg?resize=700%2C210&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"210\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd.jpg?resize=300%2C90&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>This LCD has 2 rows, and each row can display 16 characters. It also has LED backlight to adjust the contrast between the characters and the background.<\/p>\n<p>When you buy a\u00a016\u00d72 LCD, usually it doesn\u2019t come with breadboard friendly pins. So, you may need some headers.<\/p>\n<h2>Parts Required<\/h2>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-2993\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/rsz_parts.jpg?resize=453%2C302&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"rsz_parts\" width=\"453\" height=\"302\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/rsz_parts.jpg?w=800&amp;quality=100&amp;strip=all&amp;ssl=1 800w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/rsz_parts.jpg?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/p>\n<p>For this project you&#8217;ll need the following parts:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/16x2-character-lcd\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x LCD 16&#215;2<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\" rel=\"noopener noreferrer\">2x 10k Ohm Potentiometers<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 5mm LED<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 220Ohm Resistor\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper Cables<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Schematics<\/h2>\n<p>Wire all the parts by following the next schematic diagram.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/schematics_lcd_bb.jpg?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-2991\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/schematics_lcd_bb.jpg?resize=500%2C451&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"schematics_lcd_bb\" width=\"500\" height=\"451\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/schematics_lcd_bb.jpg?resize=1024%2C925&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/schematics_lcd_bb.jpg?resize=300%2C271&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/schematics_lcd_bb.jpg?w=1755&amp;quality=100&amp;strip=all&amp;ssl=1 1755w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>The next table shows a brief description of each pin of the LCD display. Make sure your LCD uses the same pinout.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd_pinout_print_screen.png?quality=100&#038;strip=all&#038;ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-2994 \" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd_pinout_print_screen.png?resize=668%2C150&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"lcd_pinout_print_screen\" width=\"668\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd_pinout_print_screen.png?resize=1024%2C230&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd_pinout_print_screen.png?resize=300%2C67&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/lcd_pinout_print_screen.png?w=1144&amp;quality=100&amp;strip=all&amp;ssl=1 1144w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/a><\/p>\n<h2>Code<\/h2>\n<p>Copy the following code and upload it to your Arduino board. The code is well commented so that you can easily understand how it works, and modify it to include in your own projects.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n Created by Rui Santos\n \n All the resources for this project:\n http:\/\/randomnerdtutorials.com\/\n \n Based on some Arduino code examples \n*\/\n\n\/\/ include the library code\n#include &lt;LiquidCrystal.h&gt;\n\n\/\/ initialize the library with the numbers of the interface pins\nLiquidCrystal lcd(12, 11, 5, 4, 3, 2);\nint potPin = A0;       \/\/ Analog pin 0 for the LED brightness potentiometer\nint ledPin = 6;        \/\/ LED Digital Pin with PWM\nint potValue = 0;      \/\/ variable to store the value coming from the potentiometer\nint brightness = 0;    \/\/ converts the potValue into a brightness \nint pBari = 0;         \/\/ progress bar\nint i = 0;             \/\/ foor loop\n\n\/\/progress bar character for brightness\nbyte pBar[8] = {\n  B11111,\n  B11111,\n  B11111,\n  B11111,\n  B11111,\n  B11111,\n  B11111,\n};\n\nvoid setup() {\n  \/\/ setup our led as an OUTPUT\n  pinMode(ledPin, OUTPUT); \n  \/\/ set up the LCD's number of columns and rows: \n  lcd.begin(16, 2);\n  \/\/ Print a message to the LCD\n  lcd.print(&quot; LED Brightness&quot;);\n  \/\/Create the progress bar character\n  lcd.createChar(0, pBar);\n}\n\nvoid loop() {\n  \/\/ clears the LCD screen\n  lcd.clear();\n  \/\/ Print a message to the LCD\n  lcd.print(&quot; LED Brightness&quot;);\n  \/\/set the cursor to line number 2\n  lcd.setCursor(0,1);\n  \/\/ read the value from the potentiometer\n  potValue = analogRead(potPin);        \n  \/\/ turns the potValue into a brightness for the LED\n  brightness=map(potValue, 0, 1024, 0, 255); \n  \/\/lights up the LED according to the bightness\n  analogWrite(ledPin, brightness); \n  \/\/ turns the brighness into a percentage for the bar \n  pBari=map(brightness, 0, 255, 0, 17);\n  \/\/prints the progress bar\n  for (i=0; i &lt; pBari; i++)\n  {\n    lcd.setCursor(i, 1);   \n    lcd.write(byte(0));  \n  }\n  \/\/ delays 750 ms\n  delay(750);        \n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/Arduino_Display_the_LED_Brightness_on_a_LCD_16_2.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Demonstration<\/h2>\n<p>After uploading the code to your Arduino board, you can rotate the potentiometer to adjust the LED brightness and change the progress bar on the LCD.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-54551\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/increase-the-LED-brightness.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"480\" height=\"270\" \/><\/p>\n<p>For a complete demonstration watch the video at the beginning of the post.<\/p>\n<h2>Wrapping Up<\/h2>\n<p>This post showed you a basic example on how to use the LCD display with the Arduino. Now, the idea is to modify the sketch and\u00a0use the display in other projects.<\/p>\n<p>If you are a beginner to the Arduino, we recommend following our\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/arduino-mini-course\/\">Arduino Mini Course<\/a>\u00a0that will help you quickly getting started with this amazing board.<\/p>\n<p>If you like Arduino, you may also like:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step-by-step Projects course<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/fingerprint-sensor-module-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Fingerprint Sensor Module with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/guide-to-neo-6m-gps-module-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">NEO-6M GPS Module with Arduino<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/control-a-12v-lamp-via-sms-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Control a 12V Lamp via SMS with Arduino<\/a><\/li>\n<\/ul>\n<p style=\"color: #222222;\">Do you have any questions?\u00a0Leave a comment down below!<\/p>\n<p style=\"color: #404040;\">Thanks for reading. If you like this post probably you might like my next ones, so please support me by <a href=\"https:\/\/randomnerdtutorials.com\/download\/\" target=\"_blank\" rel=\"noopener noreferrer\">subscribing our blog<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project we&#8217;re going to display the LED brightness on a LCD 16&#215;2 with a progress bar. This is a good Arduino beginner project for getting started with the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino &#8211; Display the LED Brightness on a LCD 16&#215;2\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-display-the-led-brightness-on-a-lcd-16x2\/#more-2973\" aria-label=\"Read more about Arduino &#8211; Display the LED Brightness on a LCD 16&#215;2\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":2990,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,264,10],"tags":[],"class_list":["post-2973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-project","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2014\/05\/rsz_lcd_thumbnail.jpg?fit=542%2C360&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/2973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=2973"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/2973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/2990"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=2973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=2973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=2973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}