16×2 LCD Pinout Diagram | Interfacing 16×2 LCD with Arduino

0
202

We come across Liquid Crystal Display (LCD) displays everywhere around us. Computers, calculators, television sets, mobile phones, digital watches use some kind of display to display the time.

An LCD screen is an electronic display module that uses liquid crystal to produce a visible image. The 16×2 LCD display is a very basic module commonly used in DIYs and circuits. The 16×2 translates o a display 16 characters per line in 2 such lines. In this LCD each character is displayed in a 5×7 pixel matrix.

lcd-display-800x389-8218322

16X2 LCD pinout diagram

7890344_origv-9633208

Pin No.

 Function

 Name

1

Ground (0V)

Ground
2

Supply voltage; 5V (4.7V – 5.3V)

 Vcc

3

Contrast adjustment; the best way is to use a variable resistor such as a potentiometer. The output of the potentiometer is connected to this pin. Rotate the potentiometer knob forward and backwards to adjust the LCD contrast.

 Vo / VEE

4Selects command register when low, and data register when highRS (Register Select )
5Low to write to the register; High to read from the registerRead/write
6Sends data to data pins when a high to low pulse is given; Extra voltage push is required to execute the instruction and EN(enable) signal is used for this purpose. Usually, we set en=0, when we want to execute the instruction we make it high en=1 for some milliseconds. After this we again make it ground that is, en=0.Enable
78-bit data pinsDB0
8DB1
9DB2
10DB3
11DB4
12DB5
13DB6
14DB7
15Backlight VCC (5V)Led+
16Backlight Ground (0V)Led-

RS (Register select)

A 16X2 LCD has two registers, namely, command and data. The register select is used to switch from one register to other. RS=0 for command register, whereas RS=1 for data register.

Command Register: The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task. Examples like:

  • initializing it
  • clearing its screen
  • setting the cursor position
  • controlling display etc.

Processing for commands happens in the command register.

Data Register: The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. When we send data to LCD it goes to the data register and is processed there. When RS=1, data register is selected.

Important command codes for LCD

Sr.No.Hex CodeCommand to LCD instruction Register
101Clear display screen
202Return home
304Decrement cursor (shift cursor to left)
406Increment cursor (shift cursor to right)
505Shift display right
607Shift display left
708Display off, cursor off
80ADisplay off, cursor on
90CDisplay on, cursor off
100EDisplay on, cursor blinking
110FDisplay on, cursor blinking
1210Shift cursor position to left
1314Shift cursor position to right
1418Shift the entire display to the left
151CShift the entire display to the right
1680Force cursor to beginning ( 1st line)
17C0Force cursor to beginning ( 2nd line)
18382 lines and 5×7 matrix

Displaying Custom Characters on 16X2 LCD

Generating custom characters on LCD is not very hard. It requires the knowledge about custom generated random access memory (CG-RAM) of LCD and the LCD chip controller. Most LCDs contain Hitachi HD4478 controller.

CG-RAM is the main component in making custom characters. It stores the custom characters once declared in the code. CG-RAM size is 64 byte providing the option of creating eight characters at a time. Each character is eight byte in size.

CG-RAM address starts from 0x40 (Hexadecimal) or 64 in decimal. We can generate custom characters at these addresses. Once we generate our characters at these addresses, we can print them by just sending commands to the LCD. Character addresses and printing commands are below.

table-5122974

In the table above you can see starting addresses for each character with their printing commands.

The first character is generated at address 0x40 to 0x47 and is printed on LCD by just sending a command 0.

The second character is generated at address 0x48 to 0x55 and is printed by sending a command 1.

How to Generate Custom Characters in CG-RAM

In LCD displays, each character is in a 5×8 matrix. Where 5 are the number of columns and 8 is the number of rows.

3737733_orig-2148451

Here is a simple example of how to create letter ‘b’ in CG-RAM.

The Array for generating ‘b’ is char b[7]={0x10,0x10,0x16,0x19,0x11,0x11,0x1E}; That is,

  • Send address where you want to create character.
  • Now create your character at this address. Send the ‘b’ character array values defined above one by one to the data register of LCD.
  • To print the generated character at 0x40. Send command 0 to command register of LCD. The table below would explain this more clearly

table-for-cgram-800x244-5413015

Interfacing a 16X2 LCD with Arduino

LCD modules form a very important in many Arduino based embedded system designs to improve the user interface of the system. Interfacing with Arduino gives the programmer more freedom to customise the code easily. Any Arduino board, a 16X2 LCD display, jumper wires and a breadboard are sufficient enough to build the circuit. The interfacing of Arduino to LCD display below.

lcd-and-arduino-800x691-7885877

Source code for 16X2LCD and Arduino.

Display the LED Brightness on a 16×2 LCD

The combination of an LCD and Arduino yields several projects, the most simple one being LCD to display the LED brightness. All we need for this circuit is an LCD, Arduino, breadboard, a resistor, potentiometer, LED and some jumper cables. The circuit connections are below.

lcd-displaying-led-brightness-800x723-5649404

The detailed project is available at displaying brightness of a LED on an LCD display


This article was first published on 21 November 2016 and was recently updated on 17 July 2021.