Interfacing LCD Display With Arduino
Français
LCDs are alphanumeric (or graphical) displays. They are frequently used in microcontroller based applications. There are many devices in the market which come in different shapes and sizes.
Some LCDs have 40 or more character lengths with the capability to display several lines. Some other LCD displays can be programmed to display graphic images. Some modules offer color displays, while some others incorporate back lighting so that they can be viewed in dimly lit conditions.
In terms of interfacing technique, we can group them in two categories: Parallel LCDs and serial LCDs.
Parallel LCDs like the popular Hitachi HD44780 series are connected to the microcontroller circuitry such that data is transferred to the LCD using more than one line and usually four data lines (4-bit mode) or eight data lines (8-bit mode) are used.
Serial LCD is connected to a microcontroller using one data line only and data is transferred using the RS232 asynchronous data communications protocol. Serial LCDs are generally much easier to use, but they are more costly than the parallel ones. In this article we will discuss only the parallel LCDs, as they are cheaper and are used more commonly in microcontroller-based projects. Arduino provides built-in libraries for interfacing the HITACHI HD44780 controller.This module is monochrome and comes in different shapes and sizes usually with character lengths of 8, 16, 20, 24, 32, and 40 and 1, 2 or 4 lines. Each character consists of 5×8 or 5×11 dot matrix.
Figure 1: A 2×16 LCD Display
This LCD display device generally has 14 pins which are marked on the PCB with some models have 16 pins if the the device has a back-light built in.
Function | Pin Number | Name | Logic State | Description |
Ground | 1 | Vss | – | 0V |
Power supply | 2 | Vdd | – | +5V |
Contrast | 3 | Vee | – | 0V to +5V |
Control of operation | 4 | RS | 0 | D0-D7 are interpreted as commands |
1 | D0-D7 are interpreted as data | |||
5 | R/W | 0 | Write data (from microcontroller to LCD) | |
1 | Read data (from LCD to microcontroller) | |||
6 | E | 0 | Access to LCD disabled | |
1 | Normal operation | |||
From 1 to 0 | data/ commands are sent to LCD | |||
Data/ commands | 7 | D0 | 0/1 | Bit 0 LSB |
8 | D1 | 0/1 | Bit 1 | |
9 | D2 | 0/1 | Bit 2 | |
10 | D3 | 0/1 | Bit 3 | |
11 | D4 | 0/1 | Bit 4 | |
12 | D5 | 0/1 | Bit 5 | |
12 | D6 | 0/1 | Bit 6 | |
14 | D7 | 0/1 | Bit 7 MSB |
Table 1: Pin descriptions
Table 1 above shows the pin configuration and pin functions of a typical 14-pin LCD. If back-light is needed and available, The LED – pin should be connected to ground and pin LED + should be connected to positive supply via a series current limiting resistor as shown in figure 3 below.
Watch the Video Tutorial
LCD Connection
Table 1 shows the description of each pin of the LCD display, a 10K variable resistor can be connected, the wiper to LCD pin 3 (Vee) to adjust the contrast the LCD. A 220 ohms series resistor is used for the LCD back light.
Figure 2: LCD on a Breadboard connected to Arduino Uno
Arduino LiquidCrystal Library
This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines).
Here is the description of few LiquidCrystal library, you can learn more from Arduino LiquidCrystal Library page
LiquidCrystal()
Description: This function is used to initialize the connections of LCDs. It creates a variable of type LiquidCrystal. You can specify to control the LCD either in 8-bit or 4-bit mode.
Syntax:
LiquidCrystal(RS, EN, D4, D5, D6, D7) // 4-bit mode D0 to D3 are not used LiquidCrystal(RS, RW, EN, D4, D5, D6, D7) // 4-bit mode D0 to D3 are not used LiquidCrystal(RS, EN, D0, D1, D2, D3, D4, D5, D6, D7) // 8-bit mode LiquidCrystal(RS, RW, EN, D0, D1, D2, D3, D4, D5, D6, D7) // 8-bit mode
- RS indicates the Arduino pin number to which LCD RS (Register Select) is connected.
- EN indicates the Arduino pin number to which LCD EN (Enable) is connected.
- RW indicates the Arduino pin number to which LCD RW (Read / Write) is connected. Since we usually write data to LCD and seldom read data from the LCD, we can connect this pin to ground instead of connecting it to Arduino.
- D0 – D8 indicates Arduino pin numbers to which LCD data pins are connected.
Example:
// initialize the LCD with Arduino pins 12 as RS, 11 as EN, 5 as D4, 4 as D5, 3 as D6 and 2 as D7 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
begin()
Description: This function initializes the LCD and specifies the dimensions (width and height) of the display. begin() needs to be called before any other LCD library commands.
Syntax:
lcd.begin(cols, rows)
Example:
// set up the LCD's number with 16 columns and 2 rows: lcd.begin(16, 2);
clear()
Description: This function clears the LCD display and sets the cursor to upper left corner.
Syntax:
lcd.clear();
home()
Description: This function sets the cursor to upper left corner.
Syntax:
lcd.home();
write()
Description: Writes a character to LCD display.
Syntax:
lcd.write(data) //data: the character to write to the display
print()
Description: This function prints text to the LCD.
Syntax:
lcd.print(data) //data: the data to print (char, byte, int, long, or string) lcd.print(data, BASE) //BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).
setCursor()
Description: This function sets the position of the LCD cursor. That means the location in which the subsequent data is displayed on the screen. In this function we can specify in which column and row we want to display our data. Note that the numbering of columns and rows are starting from 0.
Syntax:
lcd.setCursor(col, row)
cursor()
Description: This function displays the cursor (an underscore) on the LCD display at a position in which next character will be written.
Syntax:
lcd.cursor();
noCursor()
Description: This function hides the LCD cursor.
Syntax:
lcd.noCursor();
blink()
Description: This function displays blinking cursor on LCD display. This is useful in some cases where user input is required.
Syntax:
lcd.blink();
Example
Display the words “2×16 LCD Display” on first line of LCD and “studentcompanion“ on second line as shown in the circuit diagram on figure 3 below. The LCD is connected in 4-bits mode. RS and E pins are connected to Arduino pins 12 and 11 respectively. The RW pin is connected to ground and data pins D4 to D7 are connected to Arduino pins 5 to 2.
Figure 3: LCD Display connected to Arduino Uno Board
/* This example Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "2x16 LCD Display" on the first line of LCD and "studentcompanion" on the second line of LCD The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) http://www.studentcompanion.co.za */ // include the library code: #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("2x16 LCD Display"); } 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 the LCD. lcd.print("studentcompanion"); }
You can download the full project files (Arduino Sketch and Proteus Schematic design) below here. All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files).
Download: Arduino-LCD-Proteus
Download: LCD_Sketch