16×2 LCD Display interface with Arduino

Introduction

In this tutorial we will learn How to interface 16×2 LCD display using arduino. LCD displays available in various sizes 8×1, 16×1, 16×2, 16×4, 20 Char x 4 Lines. These all displays can be interfaced using this tutorial. We are more focusing on 16×2 LCD. It is commonly used.

What we are learning in this tutorial?

  1. Pin configuration of LCD.
  2. How to connect LCD with Arduino?
  3. How to move cursor on LCD?
  4. How to make custom characters?

LCD Pinout

All HD44780 (JHD16x2) driver based LCDs have 14 or 16 line interface. Backlight connections are connected to +5V supply through 330 Ohm current limiting resistor. In most cases we don’t read the display so it is better to connect R/W LCD pin to GND. For contrast setting, connect LCD contrast Pin 3 to ground through a 1K Ohm resistor. It gives optimum value of contrast. We don’t need to adjust the contrast every time using variable resistor so it is better to use fixed resistor, saves cost and space on PCB.

16x2 LCD PinOut
16×2 LCD PinOut

Connecting LCD to Arduino

Connect the LCD as shown in circuit diagram.

LCD Arduino Circuit
LCD Arduino Circuit

Arduino Commands for LCD control

Arduino software comes with “LiquidCrystal” Library. It contains many functions to control the LCD.

Let’s see one by one.

1. First step is to include the library using following command.

#include <LiquidCrystal.h>

 2. Initialize the library with the numbers of the interface pins. This library uses only 6 IO pins and always used in 4-bit mode.

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

As per our connections command becomes

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

 3. Set up the LCD’s number of columns and rows depending upon your LCD it is 16×2, 16×4, 20×4 etc.

lcd.begin(Col,Rows);

Our LCD is 16×2 so command becomes

lcd.begin(16, 2);

4. Clear display

Lcd.clear();

5. Move cursor to home position.

lcd.home();

6. Move cursor to LCD position.

This command is very useful when we are displaying any sensor value. We can quickly move the cursor to any position where we want to display text or value.

setCursor(Col, Row)

Row and col starts from zero, for line one first character it is

lcd.setCursor(0,0);

For line two coursor at first character it is

lcd.setCursor(0,1);

7. Display text on LCD.

This is most important command using this we actually display text on LCD, it is similar to Serial.print command.

lcd.print(“Hello World..”);

There are many other commands only above commands are most commonly used.
These are the cursor and display control commands. Listed below.
Cursor, noCursor, blink, noBlink, display, noDisplay, autoscroll, noAutoscroll, leftToRight, rightToLeft, scrollDisplayLeft, scrollDisplayRight, createChar

8. Custom character command

createChar(dataArray);

Arduino Code for 16×2 LCD interface

The above code displays “Hello World” and “circuits4you.com” on LCD. We have seen how to display text and custom character on LCD, also we have learned how to move cursor on LCD. You can try other commands to display cursor and text scrolling.

Leave a Reply

Your email address will not be published. Required fields are marked *