Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)

Target Amount: $2000
Amount Raised: $693

Donations Received

Top Donor: C.C. $100

X

Tutorial 12: Arduino LCD

Created on: 3 August 2012

In this tutorial you will connect a LCD (Liquid Crystal Display) to the Arduino Uno and then run the Arduino LCD example programs that are built into the Arduino IDE.

Prerequisites

It is recommended for beginners to complete all the Arduino tutorials up to and including Tutorial 10: Ten Arduino Projects for Absolute Beginners.

Read about Liquid Crystal Displays (LCD). You will also need to prepare your LCD by soldering wires or a pin header to the display unless your LCD already has connections that allow you to connect it to a breadboard. Read the article on soldering irons and on soldering. The article on soldering has a video that shows how to solder a pin header to a LCD display.

Components

Besides an Arduino Uno board, USB cable, wire links and a breadboard, you will need:


Qty Part Designator Notes Type
1 47 ohm resistor (yellow - violet - black) R1 1/4W, 5% or better

Only needed if using LCD backlight
Resistors
1 10k potentiometer RV1 Trimpot or panel mount. Used for LCD contranst Potentiometer
1 MSC-C162DYLY-4N (Truly) or PC1602LRS-FWA-B (Powertip) or similar 2 line by 16 character LCD, HD44780 compatible

The display can be with or without backlight. The two parts mentioned here both have backlights.
Semiconductor
1 16 way single in-line pin header Single in-line pin header, 16 pins (2.54mm pin spacing) to be soldered into LCD for connection to breadboard Header

Amazon.com

Amazon.co.uk


Circuit Diagram

Before wiring up your LCD to the Arduino, make sure that your LCD has the same pin numbering as the one in the circuit diagram below. If it does not, you will need to make sure that you make the correct connections between the LCD and Arduino. Also refer to the Arduino Liquid Crystal page for connections to a different LCD that has pins at the top of the LCD instead of at the bottom. The pin numbering on the physical LCD used in this tutorial can be found on the LCD page. When building the circuit, you will need to refer to the diagram or photo showing the physical pin numbering / pin names of the LCD to make sure that you are connecting the LCD correctly.


The Arduino LCD circuit diagram

The circuit diagram shows that the following connections are made:

Arduino  →
 LCD
Pin 2  →  DB7
Pin 3  →  DB6
Pin 4  →  DB5
Pin 5  →  DB4
Pin 11  →  E (Enable)
Pin 12  →  RS

The following are all connected to the Arduino GND:

  • The LCD R/W pin
  • One of the outer pins of the potentiometer
  • The LCD VSS pin
  • The LCD backlight cathode pin (BLC)

The centre pin (or wiper) of the potentiometer is connected to the LCD V0 pin.

The following are connected to the Arduino 5V pin:

  • The LCD VDD pin
  • One of the potentiometer outer pins
  • The LCD backlight anode pin (BLA) is connected to 5V through a 47Ω resistor

The first four data pins of the LCD (DB0 to DB3) are left disconnected as the LCD will be run in 4-bit mode where these pins are not needed.

The 47 ohm resistor provides current limiting for the LCD backlight and will not be needed if your LCD does not have a backlight.

The 10k potentiometer adjusts the LCD contrast. After powering up the circuit, you will need to adjust the contrast pot. until you can see the dots of the display or characters being displayed if a program (sketch) has been loaded to the Arduino and has written to the LCD.

Building the Circuit

After preparing your LCD display by soldering a pin header to it, get ready to plug it into the breadboard. Also be sure to check the datasheet for your LCD to see what the pin names are so that you can connect it correctly. Be very careful not to connect the LCD power pins the wrong way around as this will most likely destroy the LCD.

Get the breadboard, Arduino and LCD ready

Insert the LCD into the top holes of the top vertical breadboard connecting strips. Do not insert it into either of the top horizontal rails. Get four wire links ready for connecting to the LCD data lines.

Plug the LCD into the breadboard

Connect DB7 of the LCD to pin 2 of the Arduino, DB6 to pin 3 of the Arduino, DB5 to pin 4 of the Arduino and DB4 to pin 5 of the Arduino.

Connect the LCD data lines

Connect the LCD E pin to pin 11 of the Arduino and the LCD RS pin to pin 12 of the Arduino.

Connect the LCD control lines

Connect the R/W pin of the LCD to the bottom rail of the breadboard. Connect the Arduino GND to the bottom rail of the breadboard.

Connect LCD pins to GND

Connect the 10k potentiometer so that the centre pin connects to the LCD V0 pin. If using a trimpot, make sure that it is placed across the centre breadboard channel.

Connect the potentiometer

Connect the VDD pin of the LCD to one of the potentiometer outer legs. Connect this same leg to the Arduino 5V pin.

Connect the power

Connect the other outer leg of the potentiometer to the bottom GND rail of the breadboard. Connect the LCD VSS pin to GND. Connect the LCD backlight cathode BLC pin to GND if present on your LCD.

Connect the backlight and other connections

Connect the LCD backlight anode (BLA) through a 47 ohm resistor to 5V.

The finished Arduino LCD circuit on breadboard





Programming the Arduino

After connecting the LCD to the Arduino and checking the connections carefully, connect the Arduino to the PC via a USB cable. If your LCD has a backlight, this should light up. Adjust the contrast potentiometer until you can see the dots that make up the characters of the display. You can make finer adjustments to the contrast after something has been written to the display.

Loading a Test Program

To test the LCD, load the HelloWorld program to the Arduino from the Arduino IDE. It can be found in the Arduino IDE at: File → Examples → LiquidCrystal → HelloWorld. Find the details on the Arduino LiquidCrystal page.

This program displays the text "hello, world!" on the top line of the LCD and then displays an incrementing number on the bottom line of the LCD as shown in the video below. If you do not see the text, try turning the potentiometer to one extreme or the other until you can see the text. If it is still not visible, unplug the USB cable and check your connections again.

Can't see the video? View on YouTube →







Other Programs

If the HelloWorld program worked on your Arduino LCD interface, then the other LCD example programs will also work. They are listed below. Each of these programs can be found under File → Examples → LiquidCrystal.

Autoscroll

Arduino website page: LiquidCrystalAutoscroll

Demonstrates scrolling of text to the left on the LCD.

Blink

Arduino website page: LiquidCrystalBlink

Demonstrates blinking of the LCD block cursor.

Cursor

Arduino website page: LiquidCrystalCursor

Demonstrates blinking of the LCD cursor.

CustomCharacter

Arduino website page: none

This program would not verify (compile) in Arduino IDE 1.0. The IDE error message points to this line of code:

lcd.write(0);

Comment this line out like so (add two forward slashes and a space in front of the line of code):

//  lcd.write(0);

Click the Verify button again and then upload the program.

This program demonstrates drawing custom characters. A smiley face and stick man are displayed. By commenting out the line of code, the heart that is supposed to be displayed after "I" is missing.

Display

Arduino website page: LiquidCrystalDisplay

Flashes text on and off.

Scroll

Arduino website page: LiquidCrystalScroll

Demonstrates scrolling text left and right.

SerialDisplay

Arduino website page: none

Displays text sent from the Arduino Serial Monitor window on the top line of the LCD. After loading this program, open the Serial Monitor window and send some text to the LCD. See the Using the Arduino Serial Port tutorial for instructions on how to use the Arduino Serial Monitor window.

setCursor

Arduino website page: LiquidCrystalSetCursor

Writes to every character position of the LCD. Fills the entire screen with a single lower case letter starting from 'a' through to 'z'. Starts with 'a' again after writing 'z'.

TextDirection

Arduino website page: LiquidCrystalTextDirection

Demonstrates moving the cursor left and right.

← Go back to Tutorial 11: Light Activated AlarmGo to Tutorial 13: Wailing Siren →