While working with Arduino sooner than later,
you will need to display some kind of text messages.
It may be a simple "Hello world",
a calculation result or readings from a sensor
to name just a few examples.
In this video I will show you how to start
using a liquid crystal display with
2 rows of 16 characters, which in short is usually referred to as 16x2 LCD.
For the sake of this tutorial we will need
a display compatible with Hitachi HD44780,
which is probably the most common one on the
market.
Their prices start at around $5 and you can
choose different color variations.
In one of my previous videos about an Arduino
ohmmeter I used Serial Monitor to see the
readings on a computer screen.
A small LCD is probably the easiest way to
free such a project from a computer.
We’ll start from something very simple like
a static text message and then we’ll convert
my ohmmeter to display readings on the LCD.
Let’s start by connecting your liquid crystal
display to a breadboard and Arduino Uno as
shown in the wiring diagram.
Now, let’s go to Arduino IDE and select
File → Examples → LiquidCrystal → HelloWorld.
This part contains only comments, which are
omitted by the compiler, so the real code
starts here.
In order to use the LiquidCrystal library,
we need to include it first
and declare Arduino pins we want to utilize for the LCD.
In the setup section we want to define the
maximum number of characters and rows your
LCD is able to display.
It’s worth mentioning there are other types
of text liquid crystal displays, like 40x2,
16x4 and others, which are also compatible
with Hitachi HD44780 and can be used with
this Arduino library.
The next line prints our static message to
the screen, so go ahead and change it to your
own, but don’t exceed 16 characters or your
text will be clipped.
Now the loop commands.
This part sets the cursor to the first character,
in the second row.
Counting characters and rows begins with 0,
so this means first character, second row.
The last command simply prints the number
of seconds since Arduino reset.
Let’s upload the code and see the results.
As you can see the first row contains your
static message, while the second one is used
to count seconds since reset.
Going back to hardware, the 10K potentiometer
adjusts contrast,
while the 2K pot sets the backlight brightness.
You’ve just seen the basics, so let’s
jump to something more practical –
we will add the LCD to my simple ohmmeter.
Add the 2 resistors and 3 jumper wires to
the breadboard as shown in the wiring diagram.
Download the Arduino sketch from my website
and open it up using Arduino IDE.
Again, we want to use the LiquidCrystal library,
so it has to be included in the code like so.
Next we need to initialize the library
and define Arduino pins, which
are going to be used by the LCD.
Now we want to jump to the “void setup”
and define our LCD’s size,
which is 16 characters, 2 rows.
We don’t need the parts responsible for
serial communication anymore, so go ahead
and delete all 3 lines.
Finally we will start using the LiquidCrystal
library by clearing the screen
and setting the cursor to the first character, first row.
This command will print the word “Resistance”
starting from the cursor’s position, which
was set in the previous line.
Now we are going to the second row on the LCD
and printing the resistance value, which is 
stored in the variable named “R”.
That’s it, you can compile the code and
upload it to your Arduino.
It works like a charm
and if you supply power to your Arduino,
the project no longer has to be connected to the computer.
As you can see the new code is not much longer
or complicated, but it makes the whole project
so much more convenient to use.
If you want to analyze more examples, simply
go to File → Examples → LiquidCrystal.
You will find comprehensive and easy to understand
comments in each example sketch.
If you find this video useful, please like,
share it and consider subscribing to my channel.
Thanks for watching and see you next time.
