Skip to main content

Interfacing 16x2 Character LCD with Arduino

LCD (Liquid Crystal Display) are widely used display modules we find in a wide range of applications. A 16x2 character LCD display is mostly used in many applications since it is easily and cheaply available. It can display 16 characters per line and we have 2 such lines. 

Pin Diagram:

VCC is connected to supply voltage of 5V (4.7V to 5.3V)

Contrast / VEE is used to adjust the contrast of the display. A variable resistor can be used to adjust the contrast of the display by connecting the wiper pin of the variable resistor to this pin and fixed pins to the supply voltage and Ground.

RS (Register Select) A 16x2 LCD has two registers, a command register, and a data register. When it is pulled LOW command register is selected and when it is HIGH data register is selected.

The command register will have all the instructions given to the LCD like clearing the screen, position of the cursor, initializing the LCD etc. The data register stores all the data we want to display it on the LCD.

RW (Read or Write) is used to read or write data from the register. LOW is to write to the register and HIGH is to read from the register.

ENABLE (EN) sends data to the data pins a high to low pulse is given.

D0 – D7 are 8-bit data lines. Usually, the LCD is used mostly in 4-bit mode by connecting D4 to D7 pins of LCD with Arduino to save pins on Arduino.


Backlight is used to enable the display LED.

Required Hardware:
  • A 16x2 character LCD display
  • 10K potentiometer
  • 220ohms resistor
  • Arduino UNO
  • Breadboard and
  • Some Jumper wires
Connection with Arduino:

The data line D4, D5, D6 and D7 are connected with D2, D3, D4 and D5 pins of the Arduino. The RS and EN pins are connected to D12 and D11. A potentiometer of value 10K is connected to adjust the contrast of the LCD. A resistor 220 ohms is connected between 5V and backlight+. The RW pin is connected to the ground since we only write data the LCD register.


Example code:

#include <LiquidCrystal.h>; // includes library to the code
//define which pins of the LCD are connected to different pins of Arduino
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialise the LCD with the defined pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2); // setting up the LCDs no of columns and rows
}
void loop() {
lcd.setCursor(0, 0); //sets the LCD cursor to first column, first row
lcd.print(“Hello world!”); // prints Hello world message to the LCD
delay(1000);
lcd.clear(); //clears the LCD
}


By going to File à Examples à LiquidCrystal, you can find different examples with different functionalities.

Different functions of the Liquid Crystal library:

begin() – initializes the interface to the LCD screen and specifies the dimensions of the display. Syntax – lcd.begin(cols, rows);

clear() – clears the screen and places the cursor at the upper left corner. Syntax – lcd.clear();

home() – position the cursor to the upper left corner of the LCD. Syntax – lcd.home();

setCursor() – position the cursor to a specific location defined in it. Syntax – lcd.setCursor(col, row);

write() – writes a character to the LCD. Syntax – lcd.write(data);

print() – print text to the LCD. Syntax – lcd.print(data);

cursor() – displays the LCD cursor. Syntax – lcd.cursor();

noCursor() – hides the LCD cursor. Syntax – lcd.noCursor();

blink() - Display the blinking LCD cursor. If used in combination with the cursor() function, the result will depend on the particular display. Syntax – lcd.blink();

noBlink() – turns off the blinking LCD cursor. Syntax – lcd.noBlink();

display() - Turns on the LCD display, after it's been turned off with noDisplay(). This will restore the text (and cursor) that was on the display. Syntax – lcd.display();

noDisplay() - Turns off the LCD display, without losing the text currently shown on it. Syntax – lcd.noDisplay();

scrollDisplayLeft() - Scrolls the contents of the display (text and cursor) one space to the left. Syntax – lcd.scrollDisplayLeft();

scrollDisplayRight() - Scrolls the contents of the display (text and cursor) one space to the right. Syntax - lcd.scrollDisplayRight();

autoscroll() – turns on automatic scrolling of the LCD. This causes each character to output the display to push previous characters over by one space. Syntax – lcd.autoscroll();

noAutoscroll() – turns off the automatic scrolling of the LCD. Syntax – lcd.noAutoscroll();

Comments