Arduino LCD Set Up and Programming Guide (2023)

In this tutorial, I’ll explain how to set up an LCD on an Arduinoand show youall the different ways you can program it. I’ll show you how to print text, scroll text, make custom characters, blink text, and position text. They’re great forany project that outputs data, and they canmake your project a lot more interesting and interactive.

Arduino LCD Set Up and Programming Guide (1)

The display I’m using is a16×2 LCD displaythat I bought forabout $5. You may be wondering why it’scalled a 16×2 LCD. The part 16×2 means that the LCD has 2 lines, and can display 16 characters per line. Therefore, a 16×2 LCD screen can display up to 32 characters at once. It is possibleto display more than 32 characters with scrolling though.

The code in thisarticle is written for LCD’s that use the standard Hitachi HD44780 driver. If your LCD has 16 pins, then itprobably has the Hitachi HD44780 driver. These displays can be wired in either4 bit mode or 8 bit mode. Wiring the LCD in 4 bit mode is usually preferred since it uses four less wires than 8 bit mode. In practice, there isn’t a noticeable difference in performance between the two modes. In this tutorial, I’ll connectthe LCDin 4 bit mode.

BONUS: I made a quick start guide for this tutorial that you can download and go back to later if you can’t set this up right now. It covers all of the steps, diagrams, and code you need to get started.

Connectingthe LCD to the Arduino

Here’s a diagram of the pins on the LCD I’m using. The connections fromeach pin to the Arduino will be the same, but your pins might be arranged differently on the LCD. Be sure to check the datasheet or look for labels on your particular LCD:

Also, you might need to solder a 16 pin header to yourLCD before connecting it toa breadboard. Follow the diagram below to wire the LCD to your Arduino:

The resistor in the diagram above sets the backlight brightness. A typical value is 220 Ohms, but other values will work too. Smallerresistorswill make the backlight brighter.

The potentiometer is used to adjust the screen contrast. I typically use a 10K Ohm potentiometer, but other values will also work.

Here’s the datasheet for the16×2 LCD with all of thetechnical information about the display:

16×2 LCD Datasheet

Arduino LCD Set Up and Programming Guide (5)

Programming the Arduino

All of the code belowusesthe LiquidCrystal library that comes pre-installed with the Arduino IDE. A library is a set of functions that can be easily added to a program in an abbreviated format.

(Video) How to Set Up and Program an LCD on the Arduino

In order to use a library, it needsbe included in the program. Line 1 in the code belowdoes this with the command#include <LiquidCrystal.h>.When youincludea library in aprogram, all of the code in the library gets uploaded to the Arduino along with the code for your program.

Now we’re ready to get into the programming! I’ll go overmore interesting things you can do in a moment, but for now lets just run a simple test program. This program will print “hello, world!” to the screen. Enter this code into the Arduino IDE and upload it to the board:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() {}

Your LCD screen should look like this:

LCD Display Options

There are 19 different functions in the LiquidCrystal library available for us to use. These functions do things like change the position of the text, move text across the screen, or make the display turn on or off. What follows is a short description of each function, and how to use it in a program.

LiquidCrystal()

The LiquidCrystal() function sets the pinstheArduino uses to connect to the LCD. You can use any of the Arduino’s digital pins to control the LCD. Just put the Arduino pinnumbers inside the parentheses in this order:

LiquidCrystal(RS, E, D4, D5, D6, D7)

RS, E, D4, D5, D6, D7 are the LCD pins.

For example, say you want LCD pin D7 to connect to Arduino pin 12. Just put “12” in place of D7 in the function like this:

LiquidCrystal(RS, E, D4, D5, D6, 12)

This function needs to be placedbefore the void setup() section of the program.

lcd.begin()

This function sets the dimensions of the LCD. It needs to be placed before any other LiquidCrystal function in the void setup() section of the program. The number of rows and columns are specified as lcd.begin(columns, rows).For a 16×2 LCD, you would use lcd.begin(16, 2), and for a 20×4 LCD you would uselcd.begin(20, 4).

lcd.clear()

This function clears any text or data already displayed on the LCD. If you use lcd.clear() with lcd.print() and the delay() function in the void loop() section, you can make a simple blinking text program:

(Video) Arduino LCD Tutorial | How To Control An LCD

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2);}void loop() { lcd.print("hello, world!"); delay(500); lcd.clear(); delay(500);}

lcd.home()

This function places the cursor in the upper left hand corner of the screen, and prints any subsequent text from that position. For example, this code replaces the first three letters of “hello world!” with X’s:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() { lcd.home(); lcd.print("XXX");}

lcd.setCursor()

Similar, but more useful than lcd.home()is lcd.setCursor(). This function places the cursor (and any printed text) at any position on the screen. Itcan be used in the void setup() or void loop() section of your program.

The cursor position is defined withlcd.setCursor(column, row). The column and rowcoordinates start from zero (0-15 and 0-1 respectively).For example, using lcd.setCursor(2, 1) in the void setup()section of the “hello, world!” program above prints“hello, world!” to the lower line and shifts it to the right two spaces:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.setCursor(2, 1); lcd.print("hello, world!");}void loop() {}

lcd.write()

You can use this function to write different types of data to the LCD, for example the reading from a temperature sensor, or the coordinates from a GPS module. You can also use it to print custom characters that you create yourself (more on this below). Use lcd.write() in the void setup() or void loop() section of yourprogram.

lcd.print()

This functionis used to print text to the LCD. It can be used in the void setup() section or the void loop() section of the program.

To print letters and words, place quotation marks (” “) around the text. For example, to print hello, world!, use lcd.print("hello, world!").

To print numbers, no quotation marks are necessary. For example, to print 123456789, use lcd.print(123456789).

lcd.print() can print numbers in decimal, binary, hexadecimal, and octal bases. For example:

  • lcd.print(100, DEC) prints “100”;
  • lcd.print(100, BIN) prints “1100100”
  • lcd.print(100, HEX) prints “64”
  • lcd.print(100, OCT) prints “144”

lcd.cursor()

This function creates a visible cursor. Thecursor is a horizontal line placed belowthe next character to be printed to the LCD.

(Video) Arduino Tut. #4 - HD44780 LCD Setup and Programming

The functionlcd.noCursor() turns the cursor off. lcd.cursor() and lcd.noCursor() can be used together in the void loop() section to make ablinking cursor similar to what you see inmany text input fields:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() { lcd.cursor(); delay(500); lcd.noCursor(); delay(500);}

This places a blinking cursor after the exclamation point in “hello, world!”

Cursors can be placed anywhere on the screen with the lcd.setCursor() function. This code places a blinking cursor directly below the exclamation point in “hello, world!”:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() { lcd.setCursor(12, 1); lcd.cursor(); delay(500); lcd.setCursor(12, 1); lcd.noCursor(); delay(500);}

lcd.blink()

This function creates a block style cursor that blinks on and off at approximately 500 milliseconds per cycle. Use it in the void loop() section. The functionlcd.noBlink()disables the blinking block cursor.

lcd.display()

This function turns on any text or cursors that have been printed to the LCD screen. The function lcd.noDisplay() turns off any text or cursors printed to the LCD, without clearing it from the LCD’s memory.

These two functions can be used together in the void loop() section to create a blinking text effect. This code will make the “hello, world!” text blink on and off:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() { lcd.display(); delay(500); lcd.noDisplay(); delay(500);}

lcd.scrollDisplayLeft()

This function takes anything printed to the LCD and moves it to the left. It should be used in the void loop() section with a delay command following it. The function will move the text 40 spaces to the left before it loops back to the first character. This code moves the “hello, world!” text to the left, at a rate of one second per character:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.print("hello, world!");}void loop() { lcd.scrollDisplayLeft(); delay(1000);}

Text stringslonger than 40 spaces will be printed to line 1 after the 40th position, while the start of the string will continue printing to line 0.

lcd.scrollDisplayRight()

This function behaves likelcd.scrollDisplayLeft(), but moves the text to the right.

lcd.autoscroll()

This function takes a string of text and scrolls it from right to left in increments of the character count of the string. For example, if you have a string of text that is 3 characters long, it will shiftthe text 3spaces to the left with eachstep:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2);}void loop() { lcd.setCursor(0, 0); lcd.autoscroll(); lcd.print("ABC"); delay(500);}

Like the lcd.scrollDisplay() functions, the text can be up to 40 characters in length before repeating. At first glance, this function seems less useful than the lcd.scrollDisplay() functions, butit can be very useful forcreating animations with custom characters.

(Video) Arduino Tutorial 48: Connecting and Using an LCD Display

lcd.noAutoscroll()

lcd.noAutoscroll() turns the lcd.autoscroll() function off. Use this function before or afterlcd.autoscroll()in the void loop() section to create sequences of scrolling text or animations.

lcd.rightToLeft()

This function sets the direction that text is printedto the screen. Thedefault mode is from left to right using the command lcd.leftToRight(), but you may find some caseswhere it’s useful to output text in the reverse direction:

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);void setup() { lcd.begin(16, 2); lcd.setCursor(12, 0); lcd.rightToLeft(); lcd.print("hello, world!");}void loop() {}

This code prints the “hello, world!” text as “!dlrow ,olleh”.Unless you specify the placement of the cursor with lcd.setCursor(), the text will print from the (0, 1) position and only the first character of the string will be visible.

lcd.createChar()

This command allows you to create your own custom characters. Each character of a 16×2 LCD has a 5 pixel width and an 8 pixel height. Up to 8 different custom characters can be defined in a single program. To design your own characters, you’ll need to make abinary matrix of your custom character from an LCD character generator or map it yourself. This code creates a degree symbol (°):

#include <LiquidCrystal.h>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);byte customChar[8] = {0b00110,0b01001,0b01001,0b00110,0b00000,0b00000,0b00000,0b00000};void setup() { lcd.createChar(0, customChar); lcd.begin(16, 2); lcd.write((uint8_t)0);}void loop() {}

There are a lot of cool things you can make happen with these 16×2 LCDs! Try combining some of these functions and see what happens.

Here’s a video version of this tutorial so you can see what each function does on the LCD in real time:

If you foundthis article useful, subscribe via email to get notified when we publish of new posts! And as always, if you are having trouble with anything, just leave a comment and I’ll try to help you out.


FAQs

How do I program my Arduino LCD? ›

Arduino LCD Tutorial | How To Control An LCD - YouTube

Why is my LCD screen not working Arduino? ›

If your wiring is 100% correct, then check the wires themselves. As in, are they making a secure mechanical and electrical connection with the LCD and with the pins on the Arduino. Try using a breadboard instead of male-to-female jumper wires. Check that the Arduino is working properly.

Why my LCD is not working? ›

If your LCD displays no image at all and you are certain that it is receiving power and video signal, first adjust the brightness and contrast settings to higher values. If that doesn't work, turn off the system and LCD, disconnect the LCD signal cable from the computer, and turn on the LCD by itself.

What is LCD used in Arduino? ›

You can easily interface a liquid crystal display (LCD) with an Arduino to provide a user interface. Liquid crystal displays (LCDs) are a commonly used to display data in devices such as calculators, microwave ovens, and many other electronic devices..

How does an LCD work? ›

They work by using liquid crystals to produce an image. The liquid crystals are embedded into the display screen, and there's some form of backlight used to illuminate them. The actual liquid crystal display is made of several layers, including a polarized filter and electrodes.

How do I know if my LCD is working? ›

  1. To test brightness, press the Dim, Normal, and Bright buttons in the LCD Intensity Control group.
  2. To test the backlight, press Backlight Off to ensure the backlight turns on and off.
  3. To test the colors, press the Red, Green, Blue, Black, and White buttons in the Display Color group.

How can I write my name in LCD display? ›

Display your name on lcd – Project circuit diagram

Connect rs(register select) pin of 16×2 lcd to port 3 pin 5. Connect rw(read write) pin of 16×2 lcd with port 3 pin 6. Connect en(enable) pin of lcd to pin 7 of port 3. Apply 5 volts to pin 40(vcc) and 31(EA) of 8051(89c51) microcontroller.

How can I write text in LCD? ›

First select the operation which you want to perform 'Read' or 'Write'. Making R/W Pin of Lcd 0(R/W=0) will select the write operation. Now lcd is set in write mode and you can write any text to lcd. If R/W=1 lcd is set in Read mode and you can read data from lcd.

How do I make an Arduino display? ›

Using LCD Displays with Arduino - YouTube

How do I reset my LCD? ›

How to reset the LCD monitor to the default settings.
  1. On the front of the monitor, press the MENU button.
  2. In the MENU window, press the UP ARROW or DOWN ARROW buttons to select the RESET icon.
  3. Press the OK button.
  4. In the RESET window, press the UP ARROW or DOWN ARROW buttons to select either OK or ALL RESET.
Jul 23, 2019

Why is my LCD screen black? ›

Some TV displays, such as LCD screens, use a backlight to illuminate the picture. If the backlight burns out or stops working, the picture will appear black. To see if your TV's backlight is causing the problem, make sure your TV is on, and turn off the lights in the room.

How do I code my Arduino keypad? ›

Using Keypads with Arduino - Build an Electronic Lock - YouTube

How do I program a 7 segment display with Arduino? ›

In a common anode display, the positive terminal of the eight-shaped LEDs are connected together. They are then connected to pin 3 and pin 8. To turn on an individual segment, one of the pins is grounded. The diagram below shows the internal structure of the common anode seven-segment display.

How do you connect the LCD in Tinkercad? ›

Introduction: Interfacing LCD With Arduino on Tinkercad

If your LCD has 16 pins, then it probably has the Hitachi HD44780 driver. These displays can be wired in either 4 bit mode or 8 bit mode. Wiring the LCD in 4 bit mode is usually preferred since it uses four less wires than 8 bit mode.

Videos

1. Arduino Beginner Tutorial : LCD Display Programming
(Jayanam)
2. LCD Display Arduino Tutorial - Elegoo The Most Complete Starter Kit
(Hamed Adefuwa)
3. Arduino Tutorial 1: Setting Up and Programming the Arduino for Absolute Beginners
(Paul McWhorter)
4. Arduino LCD I2C - Tutorial with Arduino Uno
(Aymaan Rahman)
5. Using LCD Displays with Arduino
(DroneBot Workshop)
6. How to use LCD LCD1602 with I2C module for Arduino - Robojax
(Robojax)
Top Articles
Latest Posts
Article information

Author: Corie Satterfield

Last Updated: 11/03/2022

Views: 5846

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Corie Satterfield

Birthday: 1992-08-19

Address: 850 Benjamin Bridge, Dickinsonchester, CO 68572-0542

Phone: +26813599986666

Job: Sales Manager

Hobby: Table tennis, Soapmaking, Flower arranging, amateur radio, Rock climbing, scrapbook, Horseback riding

Introduction: My name is Corie Satterfield, I am a fancy, perfect, spotless, quaint, fantastic, funny, lucky person who loves writing and wants to share my knowledge and understanding with you.