In this project we’re going to display the LED brightness on a LCD 16×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.
Watch the video demonstration below
Introducing the LCD
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Ă—2 LCD front and the back view.
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.
When you buy a 16×2 LCD, usually it doesn’t come with breadboard friendly pins. So, you may need some headers.
Parts Required
For this project you’ll need the following parts:
- Arduino UNO – read Best Arduino Starter Kits
- 1x BreadboardÂ
- 1x LCD 16×2
- 2x 10k Ohm Potentiometers
- 1x 5mm LED
- 1x 220Ohm ResistorÂ
- Jumper Cables
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Schematics
Wire all the parts by following the next schematic diagram.
The next table shows a brief description of each pin of the LCD display. Make sure your LCD uses the same pinout.
Code
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.
/*
Created by Rui Santos
All the resources for this project:
https://randomnerdtutorials.com/
Based on some Arduino code examples
*/
// include the library code
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = A0; // Analog pin 0 for the LED brightness potentiometer
int ledPin = 6; // LED Digital Pin with PWM
int potValue = 0; // variable to store the value coming from the potentiometer
int brightness = 0; // converts the potValue into a brightness
int pBari = 0; // progress bar
int i = 0; // foor loop
//progress bar character for brightness
byte pBar[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup() {
// setup our led as an OUTPUT
pinMode(ledPin, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD
lcd.print(" LED Brightness");
//Create the progress bar character
lcd.createChar(0, pBar);
}
void loop() {
// clears the LCD screen
lcd.clear();
// Print a message to the LCD
lcd.print(" LED Brightness");
//set the cursor to line number 2
lcd.setCursor(0,1);
// read the value from the potentiometer
potValue = analogRead(potPin);
// turns the potValue into a brightness for the LED
brightness=map(potValue, 0, 1024, 0, 255);
//lights up the LED according to the bightness
analogWrite(ledPin, brightness);
// turns the brighness into a percentage for the bar
pBari=map(brightness, 0, 255, 0, 17);
//prints the progress bar
for (i=0; i < pBari; i++)
{
lcd.setCursor(i, 1);
lcd.write(byte(0));
}
// delays 750 ms
delay(750);
}
Demonstration
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.
For a complete demonstration watch the video at the beginning of the post.
Wrapping Up
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 use the display in other projects.
If you are a beginner to the Arduino, we recommend following our Arduino Mini Course that will help you quickly getting started with this amazing board.
If you like Arduino, you may also like:
- Arduino Step-by-step Projects course
- Fingerprint Sensor Module with Arduino
- NEO-6M GPS Module with Arduino
- Control a 12V Lamp via SMS with Arduino
Do you have any questions? Leave a comment down below!
Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing our blog.
Hi dear,
How can I upload code of this project.
Thanks for new project
Hi Ramesh you can either click “like” or “tweet” below the title upload the Arduino code below.
Or simply enter your email and download all my projects here:
https://randomnerdtutorials.com/download
If you’re already a subscriber simply go to the secret page I’ve emailed you before.
Thanks
Hi dear rui, I tried to load your project but not succes, how can upload.
Ramesh
Hi ramesh,
do you have your arduino well plugged and you’re uploading to the right com port?
What happen during the uploading process?
very good explanation of very thing. good job
Thank you !
Hola Rui:
En mi caso el código no corre, hay comandos en español, se debe cambiar al ingles.
Por ejemplo … lcd . comenzará (16 , 2 )… ; debe decir LCD.begin(16,2) .
He visto que muchos escriben en español y les funciona, porque? en el programa Arduino 1.0.5-r2, que utilizo, los sketch me acepta codificación de comandos en ingles.
Hola Rui:
Como se modificarĂa el sketch de modo que la visualiza la barra de progreso y su respectivo porcentaje de avanze ( 0 % ………100%).
Saludos…
Really very creative thing I really likes it .. It will surely help me in my upcoming projects thanks for sharing it
You’re welcome!
Hello Rui,
Your guides are really helpful to me, a neophite in electronics and I hope to see more of your guides.
can you explain the code.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
what is LiquidCrystal , lcd and the number ?
Class / object / function / module…. ………. ?