Monday, April 25, 2016

Arduino 16x2 LCD Basics

Good morning everyone, this one is a continuation of posts on Arduino and this particular one is about how to use a 16x2 Liquid Crystal Display. Let's take a look at the parts that we need for this simple project.

Parts needed:

1. Arduino (I'm using an Arduino UNO but any other one should work just fine)
2. USB Type A to Type B cable to connect the Arduino to a computer.
3. 16x2 LCD display (The one that I'm using is a White text on black background).
4. Bunch of Male to Male jumper wires.
5. Practice Board or you might know it as breadboard.
6. Male to Male header strip to attach pins to the Arduino. (Shown in the picture)
7. Couple Resistors.
8. 10Kohm variable resistor.
9. Arduino IDE.
10. Soldering Iron and Wire.


1. Start by attaching the Male to male header strip to the 16x2 LCD display. There should be 16 pins in there and carefully solder the strip to the display.
2. Now connect the display and Arduino via jumper wires.Wires that are needed to be connected to the display are listed below.

Pin 1 - Ground.
Pin 2 - +5V.

Pin 3 - Connect to the Wiper Terminal of the variable resistor. Variable resistor needs both Ground and +5V on it's other two terminal. This resistor is used as contrast control.

Pin 4 - Register select, connect this to Arduino pin 12.

Pin 5 - Read or Write pin. Connect it to the Ground to enable Write mode.

Pin 6 - LCD Enable Pin, connect it to the Arduino pin 11.

Pin 11 - D4 to Arduino pin 5.

Pin 12 - D5 to Arduino pin 4.

Pin 13 - D6 to Arduino pin 3.

Pin 14 - D8 to Arduino pin 2.

Pin 15 - LED+ to 5V/3.3V with a series resistor maybe a 220ohm one. I'm using a 1K one though.
Pin 16 - LED- to Ground. 

And that's it, if we connect it with the computer and upload the following code, as it is or change according to your wish we will find something like this.

The Code:

 // Example code taken from arduino tutorials and modified by Redwan Hasan.

// Let's start with including the LCD Library.
#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);
  /* Set the cursor position to horizontal zero and vertical zero, that will give us
     the top left of the first line. This line is unnecessary however, if nothing
     is declared it will be automatically started from here. */
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  lcd.print(" Line 1 ");
  // Let's give it a vertical shift so it will be on the bottom line
  lcd.setCursor(0, 1);

  // Print a message on the bottom line.
  lcd.print(" Line 2 ");

  // to change the text just replace Line 1 and Line 2 with desired text.

void loop()


Arduino with 16x2 LCD

How does it work?

Let's start with the hardware and first of all the display. This 16x2 LCD display is a 16 pin interface module consists of 16 columns x 2 rows with CHAR. DOTS : 5 x 8 (5 Columns x 8 Rows). It has pins for powering it up, adjusting contrast, register select, read or write, enable pin, Data pins and back light power pins. This display module is interfaced with the Arduino via a 4 bit mode. So the data pin DB4 to DB7 of the LCD are connected and remaining data pins DB0 to DB3 are not used.

About the code it is pretty self explanatory yet I have added notes to the code itself.

Hope you have enjoyed. Here are couple important and interesting links.

1. Soldering Pins to the 16x2 display.
2. Read My other posts here.

No comments:

Post a Comment