How to wire LCD display with Arduino: 2 codes

Get step-by-step guidance on how to connect and wire an LCD display with Arduino board for seamless integration.

How to use LCD using arduino

LCD display with Arduino

Liquid crystal Display 16×2 (LCD) is a widely used electronic device to establish communication between the real world and the electronics-based machine world.

There are multiple devices available in the market such as seven-segment displays, graphics displays, multi-segment LEDs, and so on. Still, LCD is the most preferred display device because of its amazing features. Liquid crystal display’s unique features are as follows:

  • It consists of two rows, with the capability to display 16 characters in each row.
  • Cable to display alphanumeric characters (means it can display numbers and alphabets).
  • Low power consumption.
  • Works on the principle of blocking light instead of emitting light.
  • Require less operating voltage.
  • Each character is built by a 5×8 pixel matrix.

In this tutorial, we will deal with a 16×2 Liquid crystal display that is compatible with the Hitachi Hd44780 driver. Liquid crystal Display 16×2 means, LCD can display a total of 32 characters through both rows and in other words 16 characters in the first row along with the other 16 characters in the second row. A liquid crystal display has a parallel interface that allows the microcontroller to handle multiple interface pins to control the display at a time.

LCD fundamentals

There are 16 pins available on LCD each pin’s work is described as follows:

Pin numberPin NameDescription
Pin 1GND or VSSGround pin (0 volt).
Pin 2VDD or VCCPower supply (4.7 volts to 5.3 volts).
Pin 3VEEVEE is used to adjust the brightness of the display with the help of a potentiometer (preset).
Pin 4RSRS means register to select which is used to select either data or instruction.
Pin 5R/WR/W means read/write which is preferred to select the reading or writing mode.
Pin 6EE means enable used to indicate that data is ready to write.
Pin 7  to pin 14D0  to D7Data pins.
Pin 15LED+The backlight pin is connected to +5 volt (VCC) to control the backlight
Pin 16LED-The backlight pin is connected to 0 volt (GND) to control the backlight

Hitachi driver allows LCD to operate in 4-bit mode and 8-bit mode. The 4-bit mode (which requires only 4 data lines) needs seven I/O pins and the 8-bit mode (which requires all 8 data lines) needs eleven I/O pins from Arduino Uno. The 4-bit mode has all the capabilities to display text on the LCD screen with the help of Arduino Uno. 

This was all about the LCD and its configuration now I will explain two simple projects to understand all the basics about it. The first project will help you to understand how different commands are used in Arduino and how their result shows on the LCD screen. In the second project, I will try to guide you about how rows and columns combination work to display anything on LCD with the help of Arduino.

Required component

Circuit description

For both examples, I used the same circuit configuration to make things easier for you to understand. RS pin of the LCD module is connected with pin 8 of the Arduino Uno board. RW, GND, and LED- (backlight pin) pins of the LCD module are connected to the ground pin of the Arduino Uno board. 

The VEE pin of the LCD module is connected to a 10k preset which helps to adjust the brightness of the LCD screen. VDD, LED+ (backlight pin) pins connected with +5 volt pin of the Arduino Uno board.  E pin is connected with pin 2. Preset is a three-terminal 10k register whose one terminal is connected to the 5-volt pin of the Arduino, the second terminal is connected to the ground of the Arduino Uno board and the middle terminal is connected with the VEE of the LCD module. 

For both projects, I will use 4-bit mode which is sufficient to perform all the LCD functionality with very fewer connection requirements. The 4-bit mode requires only 4 data pins to operate LCD. I have chosen the D4, D5, D6, and D7 pins of the LCD module and connected them with PINs 7, 6, 5, and 4 of the Arduino Uno board respectively. You can understand the entire connection configuration with the help of the fritzing diagram mentioned below.

Circuit diagram

LCD bb How to wire LCD display with Arduino: 2 codes

Important points about Arduino Uno

Arduino IDE has multiple sets of standard libraries for frequently used functions such as communication operations and support for some of the most common types of hardware like LCDs, servo motors, stepper motors, and so on. In both projects, we will use a built-in LiquidCrystal library, that is specially designed for the Hitachi Hd44780 driver to perform the interfacing between Arduino Uno and LCD.

In the first example, you will understand how different commands are used to display text on LCD. Here I am providing a short description for each command which will help you to understand the code.

Begin ():

It is used to specify the dimension of the LCD screen. This command is always preferred to be called at the very beginning [in void setup( )] to initialize the interface of the LCD.

Syntax:ARDUINO_LCD.begin(col, row)

Parameter:

ARDUINO_LCD: A variable of type Liquid crystal.

col: Number of columns.

row: Number of rows.

home():

This command is used to point to the position of the cursor in the upper left corner of the LCD screen.

Syntax:ARDUINO_LCD.home()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

Print():

This command is used to print the text on the LCD screen.

Syntax:ARDUINO_LCD. Print(data) or ARDUINO_LCD. Print(data, BASE)

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

Data: data to be print(it can be char, byte, int, etc.)

BASE: it is optional and used to print the base of the numbers.

setCursor():

This command is used to set the position of the cursor to display the text.

Syntax:ARDUINO_LCD.setCursor (col, row)

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

col: column number at which the cursor will display text.

row: row number at which the cursor will display text.

display():

This command is used to turn on the display.

Syntax:ARDUINO_LCD.display()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

noDisplay():

This command is used to turn off the display. This is used to blank the screen without losing the text. It means when we use this command, previously displayed text is not cleared but it is still preserved.

Syntax:ARDUINO_LCD.noDisplay()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

clear():

This command is used to clear the LCD screen and set the cursor to the upper left corner of the screen.

Syntax:ARDUINO_LCD.clear()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

blink():

This command is used to turn on the blink block-style cursor.

Syntax:ARDUINO_LCD. blink()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

noBlink():

This command is used to turn off the blink block-style cursor.

Syntax:ARDUINO_LCD. noBlink()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

cursor():

This command is used to display the underscore-style cursor at the position at which the next text will be displayed.

Syntax:ARDUINO_LCD.cursor()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

noCursor():

This command is used to hide the underscore-style cursor.

Syntax:ARDUINO_LCD.noCursor()

Parameter:

ARDUINO_LCD: a variable of type Liquidcrystal.

Code 1

/*
*How to use LCD with Arduino uno
*This video describes how different commands such as print, display, noDisplay, cursor, noCursor, blink, clear works with the help of Arduino Uno to display something on LCD.
*
*for more detail about this project please visit:https://arduinounomagic.com/2019/01/how-to-use-lcd-with-arduino-uno.html
*
*Copyright (C) 2007 Free Software Foundation, Inc. <[email protected]>
*for more projects based on Arduino uno please visit: https://arduinounomagic.com/
*/


#include<LiquidCrystal.h>
LiquidCrystal ARDUINO_LCD(8, 2, 7, 6, 5, 4);// Set RS pin=8, Enable pin=2, D4=7, D5=6, D6=5, d7=4.  

void setup() 
{  
ARDUINO_LCD.begin(16, 2);//set up number of colomn and rows of LCD
ARDUINO_LCD.home();//Positions the cursor in the upper left corner of the LCD
}

void loop() {
  // put your main code here, to run repeatedly:
ARDUINO_LCD.print("Arduino Magic"); // Prints "Arduino Uno Magic" on the LCD 
 delay(2000); // 2 seconds delay 

 ARDUINO_LCD.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be displayed 
 ARDUINO_LCD.print("How to use LCD"); // Prints "How to use LCD" on the LCD 
 delay(2000); // 2 seconds delay 
 
  ARDUINO_LCD.noDisplay(); // Turns off the display
 delay(2000);// delay
 
 ARDUINO_LCD.display();//Turns on the display
 delay(2000);//delay

 
 ARDUINO_LCD.clear(); // Clears the display 
 delay(2000);//delay
 
 ARDUINO_LCD.blink(); //Displays the blinking LCD cursor 
 delay(2000); //delay
 
 ARDUINO_LCD.noBlink(); // Turns off the blinking LCD cursor
delay(2000); //delay

 ARDUINO_LCD.cursor(); // Displays an underscore (line) at the position to which the next character will be written 
 delay(5000); //delay
 
 ARDUINO_LCD.noCursor(); // Hides the LCD cursor 
 delay(5000); //delay
 
 ARDUINO_LCD.clear(); // Clears the LCD screen 
delay(2000); //delay

}

Output

In the second example, I tried to explain to you how to set the cursor to a different location by arranging the perfect row and column combination. This is a very basic example that will help you a lot to understand how an LCD screen location arrangement can be done. In this example, I tried to display 1 to 9 numbers one by one in two different manners starting from the upper left corner along with the lower right corner. You will understand the output by watching the video.

Code 2

/*
*How to display numbers on LCD screen by Arduino uno
*This is a very basic example which will help you to understand how cursor location arrangement can be done on the LCD screen.
*
*for more detail about this project please visit:
*https://arduinounomagic.com/2019/01/how-to-use-lcd-with-arduino-uno.html

*Copyright (C) 2007 Free Software Foundation, Inc. <[email protected]>
*for more projects based on Arduino uno please visit: https://arduinounomagic.com/
*/



#include<LiquidCrystal.h>
LiquidCrystal ARDUINO_LCD(8, 2, 7, 6, 5, 4);// Set RS pin=8, Enable pin=2, D4=7, D5=6, D6=5, d7=4.  

void setup()
{ 
ARDUINO_LCD.begin(16, 2);//set up number of colomn and rows of LCD
}

void loop() {

 ARDUINO_LCD.setCursor(0,0); //set the postion of the cursor at colomn :0, row :1
 ARDUINO_LCD.print("1"); // print 1
 delay(2000); //Delay
 ARDUINO_LCD.clear();// Clear the screen
 
 ARDUINO_LCD.setCursor(1,0);//set the postion of the cursor at colomn :1, row :1
 ARDUINO_LCD.print("2");// print 2
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(2,0);//set the postion of the cursor at colomn :2, row :1
 ARDUINO_LCD.print("3");// print 3
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(3,0);//set the postion of the cursor at colomn :3, row :1
 ARDUINO_LCD.print("4");// print 4
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(4,0);//set the postion of the cursor at colomn :4, row :1
 ARDUINO_LCD.print("5"); // print 5
  delay(2000);
  ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(5,0);//set the postion of the cursor at colomn :5, row :1
 ARDUINO_LCD.print("6"); // print 6
 delay(2000);
  ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(6,0);//set the postion of the cursor at colomn :6, row :1
 ARDUINO_LCD.print("7"); // print 7
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(7,0);//set the postion of the cursor at colomn :7, row :1
 ARDUINO_LCD.print("8"); // print 8
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(8,0);//set the postion of the cursor at colomn :8, row :1
 ARDUINO_LCD.print("9"); // print 9
 delay(2000);
 ARDUINO_LCD.clear();

 ARDUINO_LCD.setCursor(15,1); //set the postion of the cursor at colomn :15, row :2
 ARDUINO_LCD.print("1"); // print 1
 delay(2000);
 ARDUINO_LCD.clear();
 
 ARDUINO_LCD.setCursor(14,1);//set the postion of the cursor at colomn :14, row :2
 ARDUINO_LCD.print("2"); // print 2
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(13,1);//set the postion of the cursor at colomn :13, row :2
 ARDUINO_LCD.print("3"); // print 3
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(12,1);//set the postion of the cursor at colomn :12, row :2
 ARDUINO_LCD.print("4"); // print 4
delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(11,1);//set the postion of the cursor at colomn :11, row :2
 ARDUINO_LCD.print("5"); // print 5
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(10,1);//set the postion of the cursor at colomn :10, row :2
 ARDUINO_LCD.print("6"); // print 6
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(9,1);//set the postion of the cursor at colomn :9, row :2
 ARDUINO_LCD.print("7"); // print 7
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(8,1);//set the postion of the cursor at colomn :8, row :2
 ARDUINO_LCD.print("8"); // print 8
 delay(2000);
 ARDUINO_LCD.clear();
  
 ARDUINO_LCD.setCursor(7,1);//set the postion of the cursor at colomn :7, row :2
 ARDUINO_LCD.print("9"); // print 9
 delay(2000);
 ARDUINO_LCD.clear();
   

}

Output

 Hope you like the article.

Leave a Reply

Your email address will not be published. Required fields are marked *