How to Use an LCD Display - Arduino Tutorial

182,420

335

30

About: Arduino Tutorials by Codebender.cc Team

Intro: How to Use an LCD Display - Arduino Tutorial

The LiquidCrystal library allows you to control LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually find them by the 16-pin interface.

In this tutorial you will learn how to use LCD 16x2 display (and 20x4) with Arduino uno.

You will also learn how to use lcd.begin(), lcd.print() and lcd.setCursor() functions

So, let's get started!

Step 1: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • LCD 16x2
  • Potentiometer (e.g. 4.7K)

Step 2: About the LCD Dislpay Pinout

The parallel interface consists of the following pins:

  • Power Supply pins (Vss/Vcc): Power the LCD
  • Contrast pin (Vo): Control the display contrast
  • Register Select (RS) pin: Controls where in the LCD's memory you're writing data to
  • Read/Write (R/W): Selects reading mode or writing mode
  • Enable pin: Enables writing to the registers
  • 8 data pins (D0 -D7): The states of these pins (high or low) are the bits that you're writing to a register when you write, or the values you're reading when you read.
  • Backlight (Bklt+ and BKlt-) pins: Turn on/off the LED backlight

The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit mode requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins.

For displaying text on the screen, you can do most everything in 4-bit mode, so in this tutorial we will use 4-bit mode.

Step 3: The Circuit

The connections are easy, see the image above with the breadboard circuit schematic.

Step 4: The Code

Here's the code, embedded using codebender!

The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20x4).

The lcd.print("--message--") command print a message to first column and row of lcd display. The "message" must have maximum length equal to lcd columns number. For example, for 16 columns display max length is equal with 16 and for 20 columns display max length is equal with 20.

The lcd.setCursor(0,1) command will set cursor to first column of second row. If you have an LCD 20x4 and you want to print a message to column five and third row you have to use: lcd.setCursor(4,2).

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!

You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code. For example, try to change message on first and second row.

Step 5: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use an LCD display with Arduino uno.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

8 People Made This Project!

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Furniture Contest 2018

    Furniture Contest 2018
  • Audio Contest 2018

    Audio Contest 2018

30 Discussions

0
None
CoolM3

Tip 15 days ago

Thanks working properly

0
None
yadea

Question 2 months ago

Hi,

How do I print a white box? I am planning to print white boxes to act like a progressbar.

Thank you.

0
None
chrisjlionelToreE

Reply 9 months ago

Then ToreE, how will you adjust the contrast?

0
None
ToreEchrisjlionel

Reply 9 months ago

I simply don't. Once I've found the most comfortable contrast level, I hardwire resistors with fixed levels. No need to adjust an optimal settinng. :)

0
None
codebender_ccrene14

Reply 3 years ago on Introduction

Hello, yes you will need one 10K pot. Why? Because with this you can adjust the contrast of yours display.

0
None
yash0011

1 year ago

it was great fun i did it

0
None
yash0011

1 year ago

what if i do not have the potentiometer

0
None
TimC211TimC211

Reply 1 year ago

Although I DID use an Arduino MEGA

0
None
woutermoors

1 year ago

do you need to use 3 PMW pin's

0
None
woutermoors

1 year ago

what kinds of potentiometers can be used? Because i'm not able to find the one used in the tutorial

0
None
ritihnhaaaaRafayJ

Reply 2 years ago

I agree w/ u!!!11!!
p.s. nice pic! ;) :*

0
None
Jens2301

2 years ago

Thank you so much, it works perfect :)