Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...

LCD is the most commonly used part when you start playing with the Arduino. It will help you whenever you will want to display the data. So, in this post you are going to learn about Arduino LCD 16X2  interfacing.

You may be wondering that what does this 16X2 means. This means that LCD has 16 columns and 2 rows. Other LCD’s with 16X1 and 16X4 displays are also available. Each character of LCD consists of 5X10=50 pixels. These LCD’s are compatible with the Hitachi HD44780 driver which controls the pixels.

Required Components

The components required for Arduino LCD interfacing are as follows

  • 16X2 LCD
  • Arduino Uno
  • Headers to solder to the LCD
  • 10K potentiometer
  • 220 ohm resistor
  • Connecting wires

Pin out of LCD

VSS: This is the ground pin.

VDD: This is the 5V pin.

V0: This pin controls the contrast of the LCD.

RS (Register Select Pin): This pin control where you are writing data in the LCD’s memory. There are two types of registers; Data register which holds what goes on the screen and the instruction register where the LCD looks for the next instruction.

R/W (Read/Write Pin): This pin selects the mode; Reading mode or Writing mode. Connecting it to ground will put the LCD in the read mode.

E (Enable Pin): This pin enables the writing to the registers.

Data Pins: There are 8 data pins (D0-D7). The high or low state of these pins represents the bits that you are writing to register in the write mode or the values you are reading in the read mode.

The last two pins are for the LCD back light. Some LCD’s have 16 pins and some have 14 pins. If you have a 14 pin LCD then it means that there is no back light.

A (LED+): This pin is the positive connection of the back light.

K (LED-): This pin is the negative connection of the back light.

16X2 lcd pin out

LCD Pin out

Circuit Diagram and Explanation

First of all, solder the 16 pin header with the LCD then make the connections.

The LCD can be connected in the 4 bit as well as 8 bit mode. In the 4 bit mode we have to use only the 4 data pins while in the 8 bit mode we will have to use all the 8 data pins. You can do almost everything in the 4 bit mode, so in this example we are going to connect it in the 4 bit mode.

The connections of LCD with Arduino are as follows

16X2 LCD Arduino Uno
VSS GND
VDD 5V
V0 Middle of 10K potentiometer
Connect the two ends of potentiometer to GND and 5V
RS Pin 7
R/W GND
E Pin 6
D4 Pin 5
D5 Pin 4
D6 Pin 3
D7 Pin 2
A To 5V through 220 ohm resistor
K GND
arduino lcd interfacing

Arduino LCD Interfacing

Code for Simply displaying the data on the LCD Screen

Before uploading the code in the Arduino, you will have to download the library for the LCD. The library will have the built in functions which will help us to make the code simple. Download library from below link.

DHT22 Library

After downloading, extract it into the library folder of Arduino.

#include <LiquidCrystal.h>  //Initializing the library for LCD
LiquidCrystal lcd(7,6,5,4,3,2);  //Initializing the pins where we have connected the LCD
void setup()      //Anything written in it will only run once
{
lcd.begin(16, 2);     //Initializing the interface on the LCD screen
lcd.setCursor(0, 0);// set the cursor to column 0, line1
lcd.print(" Welcome to   ");//print name
lcd.setCursor(0, 1); // set the cursor to column 0, line 2
lcd.print(" Arduino World ");//print name
}
void loop()     //Anything written in it will run again and again
{
}

Code Explanation

First of all, you will have to include the liquid crystal library that contains the built in functions which we are going to use in the code. These functions will make our projects easier.

Lcd.begin(16,2) command will initialize the interface on the LCD screen and also will initialize the dimensions of the LCD i.e. 16X2 or 16×4.

#include <LiquidCrystal.h>  //Initializing the library for LCD
LiquidCrystal lcd(7,6,5,4,3,2);  //Initializing the pins where we have connected the LCD
void setup()      //Anything written in it will only run once
{
lcd.begin(16, 2);     //Initializing the interface on the LCD screen

lcd.setCursor() command is used to set the cursor at the column 0, line 1 or column 0 line 2 depending on what dimensions you give.

lcd.print(“”) will print whatever there will be inside the brackets on the LCD screen.

lcd.setCursor(0, 0);// set the cursor to column 0, line1
lcd.print(" Welcome to   ");//print name
lcd.setCursor(0, 1); // set the cursor to column 0, line 2
lcd.print(" Arduino World ");//print name

Code for shifting the data towards left on the LCD Screen

In this code, the data written on the LCD will keep shifting towards the left side. All the functions are similar to the previous code except the lcd.scrollDisplayLeft() function. This will keep shifting the data on the left side of LCD.

#include <LiquidCrystal.h>             //Initializing the library for LCD
LiquidCrystal lcd(7,6,5,4,3,2);        //Initializing the pins where we have connected the LCD
void setup()                                        //Anything written in it will only run once
{
lcd.begin(16, 2);                                 //Initializing the interface on the LCD screen
}
void loop()                                          //Anything written in it will run again and again
{
lcd.setCursor(0, 0);                            // set the cursor to column 0, line1
lcd.print("Welcome to   ");               //print name
lcd.setCursor(0, 1);                            // set the cursor to column 0, line 2
lcd.print("Electronicshobbyists.com ");  //print name
delay(750);                                         //delay of 0.75sec
lcd.scrollDisplayLeft();                     //shifting data on LCD
}

Code for LCD Counter

In this code, we have made a counter that will count from 0 to 60. We have used the while loop, which will check that whether the count is less than 60 or not. If the count will less than 60, then it will add 1 count into it.

#include <LiquidCrystal.h>           //Initializing the library for LCD
LiquidCrystal lcd(7,6,5,4,3,2);  //Initializing the pins where we have connected the LCD
int c=0;
void setup()      //Anything written in it will only run once
{
lcd.begin(16, 2);     //Initializing the interface on the LCD screen
lcd.setCursor(0,0);     //Set cursor at column 0, line 1
lcd.print("LCD COUNTER");
delay(100);
lcd.setCursor(0,1);   //Set cursor at column 0, line 2
lcd.print(c);     // Printing the count on LCD screen.
while(c<60){
c=c+1;
delay(1000);
lcd.setCursor(0,1);
lcd.print(c);      //Printing the last count
}
}
void loop()     //Anything written in it will run again and again
{
}

Video

If you have any questions. Feel free to ask.

JOIN OUR NEWSLETTER
We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a Reply

Your email address will not be published.

Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...
Skip to toolbar