Introduction

One of the most widely used information display elements on Arduino is the 16×2 LCD liquid crystal display.

Liquid crystals enable the creation of flat screens with low power consumption. They use polarizing filters to polarize light. Crystals do not emit light, only their transparency varies, so they need to be illuminated.

The display has LED backlighting and can show two lines of 16 characters. Each character is a pixel rectangle. Each pixel in each rectangle can be controlled to create specific characters.

The screen is called 16×2 because it has 16 columns and 2 rows. There are many other possible screen combinations, such as 8×1, 10×2, 16×1, but 16×2 is the best known.

With a 16×2 screen, we’ll have 32 characters. A character is made up of 5×8 =40 pixels. This number of pixels is necessary to distinguish one character from another.

Initially available in black and white and in a small size, it is used in calculators, multimeters and watches because of its low power consumption.

 

It is currently used for full-color display in a wide range of electronic applications.

You can use it in a wide range of projects, including displaying the value of a temperature sensor, the time of day, or a small screen for a 3d printer.

 

Let’s take a look at the various LCD display pins:

  • Vss: Connect to ground
  • Vdd: Connect to +5V
  • VEE or VO: Connect to a potentiometer to adjust contrast
  • Rs: Control memory register
  • R/W: Select write or read
  • E: When low, causes the LCD module to execute instructions.
  • D0-D7: Read and write data
  • A and K: Control backlighting

Can the LCD screen be used for outdoor projects?

Many outdoor projects require a display, such as a mini weather station or sensor data. The LCD screen is therefore usable if protected from the rain. We therefore advise you to place it high up with some form of protection, such as glass, or in a closed box.

Library LiquidCrystal

To use the LCD screen, you need a library: LiquidCrystal.zip. There’s a set of functions in it that will simplify your code and the use of the 16×2 screen.


a) Installation

To install it, you need to open the Arduino IDE and click on sketch then include library and add .ZIP Library as shown below:

You can also install it from the library manager by clicking on Manage Librairies rather than Add .ZIP Library and then typing Liquid Crystal.

If you’re having trouble installing it, take a look at our course on libraries.


b) Library functions

The Liquid Crystal library is made up of several functions to make it easier for you to use.

  • LiquidCrystal (): Initializes the pins associated with the LCD screen.
  • begin(column,line) : Initializes the LCD screen with the screen dimensions.
  • clear() : Clears the screen and returns the cursor to the top left.
  • home() : Returns cursor to top left without clearing screen.
  • setCursor(column, row) : Positions cursor on screen.
  • write() : Writes a character to the screen.
  • Print() : Writes a character string to the screen.
  • createChar() : Allows you to create your own character. An example will be shown at the end of this course.

Display text on screen

Let’s take a look at how to display text on the 16×2 screen. This can be very useful for displaying information such as the time of day or sensor response. The circuit is a little complex to build… But to compensate, the code is very simple and easy to understand, thanks to the library.

 

To simplify the circuit if you wish, you can remove the potentiometer from the circuit and replace the yellow wire on the diagram by a wire going to 5V. You won’t be able to adjust the screen brightness, it will be at its maximum, but you’ll need fewer components and wires.

Here’s the program associated with the project:

#include <LiquidCrystal.h> // The screen library

// We initialize the screen with the pins for which we've connected it
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // Define the number of rows and columns on the screen.
  lcd.begin(16, 2);
  // Display the message
  lcd.print("Arduino Factory");
}

void loop() {
  // Set cursor to column 0 line 1
  lcd.setCursor(0, 1);
}

The result is as follows: