Liquid crystal displays

A liquid-crystal display (LCD) is a flat-panel display that uses the light-modulating properties of liquid crystals. Liquid crystals do not emit light directly, instead using a backlight or reflector to produce images in colour or monochrome. LCDs are available to display arbitrary images, as in a general-purpose computer display or fixed images with low information content, which can be displayed or hidden, such a series of characters or digits, and 7-segment displays.

An LCD consists of a number of layers that include a polarizer, a set of transparent electrodes, a liquid-crystal element, a transparent back electrode, a second polarizer, and a mirror or a backlight. The transparent top electrodes are used to generate the individual segments of a digit, character, and so on, while the transparent back electrode forms a common plane, often referred to as the back plane. The top electrode segments and the back electrode are wired to external contacts. With no potential difference between a given top electrode and the back electrode, the region where the top electrode is located appears green in colour against a green background (see the LCD module in figure above). However, when a potential is applied between a given top electrode and back electrode, the region where the top electrode is located appears dark against a green background.

Character LCDs are used to display alphanumeric characters and other symbols. These displays are used in cell phones, calculators, vending machines, and many other devices that provide the user with simple textual information. A character LCD module uses a small grid of lights to display letters, numbers, and simple symbols. The most common grid layout is a 5X8 grid of dots. The LCD displays each character by turning on or off each crystal dot in the grid to represent the character.

Character LCDs can be purchased in various sizes, which are measured by the number of rows and columns of character they can display. The most common character LCD modules used in the Arduino world is the 16 X 2 LCD device, which can display two lines of 16 characters. Most of them include a backlight and allow you to choose the colour of the character and the background colour.

Almost all character LCD modules are controlled by Hitachi’s HD44780 driver IC. This driver is built into the LCD module. The standard LCD module comes with a 14-pin interface: eight data lines (D0-D7), three control lines (RS, W/R, and E), and three power lines (VDD, VSS, and VEE), plus the backlight power pins.

VDD (pin 2) and VSS (pin 1) are the module’s positive and negative power supply leads. Usually, VDD is set to +5V, while VSS is grounded. VEE (pin 3) is the display’ s contrast control. By changing the voltage applied to this lead, the contrast of the display increases or decreases. A potentiometer placed between supply voltages, with its wiper connected to VEE, allows for manual adjustment.

D0-D7 (pins 7-14) are the data bus lines. Data can be transferred to and from the display either as a single 8-bit byte or as two 4-bit nibbles. In the latter case, only the upper four data lines (D4-D7) are used

RS (pin 4) is the Register Select line. When this line is low, data dytes transferred to the display module are interpreted as commands, and data bytes read from the display module indicate its status. When the RS line is set high, character data can be transferred to and from the display module.

R/W (pin 5) is the Read/Write control line. To write commands or character data to the module, R/W is set low. To read character data or status information from the module, R/W is set high.

E (pin 6) is the Enable control input, which is used to initiate the actual transfer of command or character data to and from the module. When writing to the display, data on the D0-D7 lines is transferred to the display when the enable input receives a high-to-low transition. When reading from the display, data become available to the D0-D7 lines shortly after a low-to-high transition occurs at the enable input and will remain available until the signal goes low again.

LED+ (pin 15) and LED- (pin 16) power the LED backlight. Depending on the LCD device, you may or may not have to use a resistor to connect pin 15 to the +5 volts. Go ahead and use a small resistor, such as 220 ohms to help limit the current going to the LED backlight.

Using a Character LCD in a Sketch

To demonstrate the use of a character LCD module with Arduino, we are wiring an 2X16 LCD module to the Nano Arduino board, as is shown in the following figure.

We will first explain the required functions and how they work through some simple demonstrations. Enter and upload the basic sketch shown in Listing bellow:

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);&nbsp;&nbsp; // pins for RS, E, D4, D5, D6, D7
void setup()
   lcd.begin(16, 2);
void loop()
   lcd.setCursor(5, 0);
   lcd.setCursor(6, 1);

The Figure shows the result of the Listing

Now to see how the sketch works. First we need to include two initial lines in the sketch. Their purpose is to include the library for LCD modules (which is automatically installed with the Arduino IDE), and then we need to tell the library which pins are connected to the Arduino. To do this, we add the following lines before the void setup() method:

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);&amp;nbsp; //pins for RS, E, D4, D5, D6, D7

If you need to use different digital pins on the Arduino, adjust the pin numbers in the second line of this code.

Next, in void setup(), we tell the Arduino the size of the LCD in columns and rows. For example, here’s how we’ d tell the Arduino that the LCD haw two rows of 16 characters each:


Displaying Text

With the LCD setup complete, clear the LCD’s display with the following:


Then, to position the cursor, which is the starting point for the text, use this:

lcd.setCursor(x, y);

Here, x is the column (0 to 15) and y is the row (0 or 1). So, for example, to display the word text, you would enter the following:


Now that you can position and locate text, let’s move on to displaying variable data.

Displaying Variables or Numbers

To display the contents of variables on the LCD screen, use this line:


If you are displaying a float variable, you can specify the number of decimal places to use. For example, lcd.print(pi, 3); in the following example tells the Arduino to display the value of pi to three decimal plates.

float pi = 3.141592654;
lcd.print(“pi: “);
lcd.print(pi, 3);

When you want to display an integer on the LCD screen, you can display it in hexadecimal or binary, as shown in following listing

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int k = 170;
void setup()
   lcd.begin(16, 2);

void loop()
   lcd.setCursor(0, 0);
   lcd.print("Binary: ");
   lcd.print(k, BIN);
   lcd.setCursor(0, 1);
   lcd.print("Hexadecimal: ");
   lcd.print(k, HEX);

The LCD will then display the text shown in Figure bellow:

Other LCD commands

lcd.display( ); the characters are shown on the display (default).
lcd.noDisplay( ); any characters are hidden; they are kept in memory.

lcd.cursor( );  the cursor indicator is displayed.
lcd.noCursor( ); the cursor indicator is not shown.

lcd.blink( ); the cursor blinks.
lcd.noBlink( ); the cursor stops blinking.

lcd.scrollDisplayLeft( ); the display is scrolling left by one character position.
lcd.scrollDisplayRight( );  the display is scrolling right by one character position.