How to Use an LCD Display - Arduino Tutorial

265,467

358

43

Introduction: How to Use an LCD Display - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

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!

12 People Made This Project!

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Automation Contest

    Automation Contest
  • Make it Glow Contest

    Make it Glow Contest

43 Comments

0
BasharO
BasharO

Question 10 months ago on Introduction

Hi,
When I tried the code of lcd 16*2 after 2-3 second I have get this screen...
Can anyone help me.. Thanks

٢٠٢٠٠٤١٢_١٣٣٥٠١.jpg
0
funniemanja
funniemanja

2 years ago

i have a problem. when i power my lcd only one line of it is working. i have tried to charge lcds but no charges. what should i do?

0
this-djs
this-djs

Reply 2 years ago

have you used "lcd.setCursor(0, 1);" ?

0
funniemanja
funniemanja

Reply 1 year ago

yes i did

0
SatyaD4
SatyaD4

Question 1 year ago

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hello World!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
//Print a message to second line of LCD
lcd.print("Codebender");
}


i worked on this code and its fine same code will work with 20x4-line-lcd-display.

0
ChiefME
ChiefME

1 year ago

Think you may have a slight error for the 4-row LCD. In your statement:
"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)."
Shouldn't the code read:
lcd.begin(20,4)

0
TimC211
TimC211

4 years ago

I made it, but the LCD didn't work?!?

0
userCatnip
userCatnip

Reply 1 year ago

same here m8, i connected/rebuilt the lcd display contraption but it wouldnt connect to Arduino:(

0
TimC211
TimC211

Reply 4 years ago

YOU NEED TO HELP ME

0
TimC211
TimC211

Reply 4 years ago

Although I DID use an Arduino MEGA

0
Surya Rathinakumar
Surya Rathinakumar

Question 1 year ago on Step 4

I wrote the code and dumped into arduino.
But display does not show the alphabetic letters. It shows only dark boxes..

IMG_20190331_005146.jpg
0
NMBH
NMBH

2 years ago

Hello,

I have a small problem, i took the code from bellow, run it, there are no errors.. but still the display doesn't show anything ? did i missed something ? Please help.

/* Arduino Tutorial: Learn how to use an LCD 16x2 screen
More info: http://www.ardumotive.com/how-to-use-an-lcd-dislp... */
//Include LCD library
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Hello World!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
//Print a message to second line of LCD
lcd.print("Codebender");
}




i attached also a picture with the arduino.

Thank you in advance,

NMBH.

arduino.jpg
0
woutermoors
woutermoors

4 years ago

do you need to use 3 PMW pin's

0
BremPaul4341
BremPaul4341

Reply 2 years ago

If you are using an Arduino MEGA 2560 (or any other prossesor variants of the MEGA) you do need to use PWM pins and it will work fine.

0
HimanshiG3
HimanshiG3

2 years ago

why are only four data pins of lcd are used instead of all seven data pins

0
provashporia
provashporia

2 years ago

I want to type characters from 4 cross 4 matrix keyboard and display on lcd.

0
CoolM3
CoolM3

Tip 2 years ago

Thanks working properly

0
yadea
yadea

Question 2 years ago

Hi,

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

Thank you.