LCD (Liquid Crystal Display) Arduino Interface

LCD (Liquid Crystal Display) Arduino Interface 



LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segment and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.
16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

Pins of the LCD

There are total 16 pins on the LCD which are used in different ways:
These include 
8 Data pins
2 Power pins
1 Cantrast pin
1 Enable pin
1 Register pin
1 Read / Write pin
2 Back Light pins

 PIN ASSIGNMENT

No. Symbol  Level Function
1   Vss --      0V
2   Vdd --    +5V Power Supply
3   V0 --      for LCD contrast (5 volt through potentiometer)
4   RS --      H/L Register Select:  H:Data Input   L:Instruction Input
5   R/W       H/L  H--Read L--Write
6   E           H ,  H-L Enable Signal
7   DB0       H/L
8   DB1       H/L
9   DB2       H/L                 Data bus used in 8 bit transfer (pin no 7 to 10 i.e DB0 to DB3)
10 DB3       H/L      
11 DB4       H/L              
12 DB5       H/L                 Data bus for both 4 and 8 bit transfer (pin no 11 to 14 i.e DB4 to DB7)
13 DB6       H/L
14 DB7       H/L
15 BLA --    BLACKLIGHT +5V
16 BLK --    BLACKLIGHT 0V

Connection With Arduino

CONNECTIONS

Connection of power pins
Connect the power pins to the Arduino i.e connect Ground to pin 0 and 5 v to pin 2. 
For the contrast of the LCD connect a potentiometer to pin no 3
Connect one end of potentiometer to 5 V and the other to the Ground and the center to the pin no 3.
Refer to the Picture below.

Power Pins 5v and GND


Connection of data pins
Here you will use only 4 pins for the data transfer to the LCD i.e pin no 11 to 14 for the 4 bit data transfer.
RS, E and Data pins

  • Connect DB4 ie pin 11 to pin no 4 of Arduino.
  • Connect DB5 ie pin 12 to pin no 5 of Arduino.
  • Connect DB6 i.e pin 13 to pin no 6 of Arduino.
  • Connect DB7 i.e pin 14 to pin no 7 of Arduino.


Pins for Back light of LCD
Pin no 15 and 16 of the LCD display are pins for the Back Light of the LCD so they are connected to the same power supply as mentioned below.
Connect pin no 15 to 5 V.
Connect pin no 16 to Ground.

Enable pin
Pin no 6 of the LCD is the Enable pin for the LCD.
Connect the Enable pin (i.e pin 6 of LCD) to pin no 3 of Arduino.

Register Select Pin 
Pin no 4 of the LCD is Register Select pin. 
Connect this pin to pin no 2 of Arduino.

Read Write pin
Pin no 5 on the LCD display is the Read Write pin.
Connect this pin to the Ground

Contrast pin
Pin no 3 of the LCD display is Contrast pin which is used for controlling the contrast of the LCD display.
This pin is connected to LCD through a potentiometer and it is needed to set the potentiometer to a particular reading at which the display can be Read.
For Setting contrast follow the given steps:

  • Plug the potentiometer on the breadboard 
  • Connect one extreme pin to Vcc
  • and other extreme pin to GND
  • the middle pin of potentiometer to Vo pin of LCD
  • then rotate the knob of potentiometer from zero to maximum and stop where a decent display is obtained

Connection of potentiometer

Code For LCD

For the Arduino code click here

Header File Used  #include <LiquidCrystal.h>

You can access to many inbuilt functions
Some are given below:

  • LiquidCrystal()

  • Description
  •     Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters.

  • Syntax

  1. LiquidCrystal(rs, enable, d4, d5, d6, d7) 
  2. LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) 
  3. LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7) 
  4. LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)


  • Parameters
  • rs :          The number of the Arduino pin that is connected to the RS pin on the LCD
  • rw :         The number of the Arduino pin that is connected to the RW pin on the LCD (optional)
  • enable :   The number of the Arduino pin that is connected to the enable pin on the LCD

  • d0, d1, d2, d3, d4, d5, d6, d7:  
    • The numbers of the Arduino pins that are connected to the corresponding data pins on the LCD.  ( d0, d1, d2, and d3 ) are optional. If omitted, the LCD will be controlled using only the four data lines (d4, d5, d6, d7).

  • begin()

  • Description
  • Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display. begin() needs to be called before any other LCD library commands.

  • Syntax
  • lcd.begin(cols, rows)

  • Parameters
  • lcd:      a variable of type LiquidCrystal
  • cols:    the number of columns that the display has
  • rows:   the number of rows that the display has 

  • clear()

  • Description
  • Clears the LCD screen and positions the cursor in the upper-left corner.

  • Syntax
  • lcd.clear()

  • Parameters
  • lcd:  a variable of type LiquidCrystal

  • home()
  • Description
  • Positions the cursor in the upper-left of the LCD. That is, use that location in outputting subsequent text to the display. To also clear the display, use the clear() function instead.

  • Syntax
  • lcd.home()

  • Parameters
  • lcd: a variable of type LiquidCrystal


  • setCursor()
  • Description
  • Position the LCD cursor; that is, set the location at which subsequent text written to the LCD will be displayed.

  • Syntax
  • lcd.setCursor(col, row)

  • Parameters
  • lcd:   a variable of type LiquidCrystal
  • col:   the column at which to position the cursor (with 0 being the first column)
  • row: the row at which to position the cursor (with 0 being the first row) 

  • write()
  • Description
  • Write a character to the LCD.

  • Syntax
  • lcd.write(data)

  • Parameters
  • lcd: a variable of type LiquidCrystal
  • data: the character to write to the display

  • Returns
  • byte
  • write() will return the number of bytes written, though reading that number is optional

  • print()
  • Description
  • Prints text to the LCD.

  • Syntax
  • lcd.print(data) 
  • lcd.print(data, BASE)

  • Parameters
  • lcd: a variable of type LiquidCrystal
  • data: the data to print (char, byte, int, long, or string)
  • BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).

  • Returns
  • byte
  • print() will return the number of bytes written, though reading that number is optional

  • cursor()
  • Description
  • Display the LCD cursor: an underscore (line) at the position to which the next character will be written.

  • Syntax
  • lcd.cursor()

  • Parameters
  • lcd: a variable of type LiquidCrystal

  • noCursor()
  • Description
  • Hides the LCD cursor.

  • Syntax
  • lcd.noCursor()

  • Parameters
  • lcd: a variable of type LiquidCrystal

  • blink()
  • Description
  • Display the blinking LCD cursor. If used in combination with the cursor() function, the result will depend on the particular display.

  • Syntax
  • lcd.blink()

  • Parameters
  • lcd: a variable of type LiquidCrystal


  • noBlink()
  • Description
  • Turns off the blinking LCD cursor.

  • Syntax
  • lcd.noBlink()

  • Parameters
  • lcd: a variable of type LiquidCrystal

  • display()
  • Description
  • 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()

  • Parameters
  • lcd: a variable of type LiquidCrystal

  • scrollDisplayLeft()
  • Description
  • Scrolls the contents of the display (text and cursor) one space to the left.

  • Syntax
  • lcd.scrollDisplayLeft()

  • Parameters
  • lcd: a variable of type LiquidCrystal
  • Similarly the function lcd.scrollDisplayRight for Display the text on the Right

  • autoscroll()
  • Description
  • Turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters over by one space. If the current text direction is left-to-right (the default), the display scrolls to the left; if the current direction is right-to-left, the display scrolls to the right. This has the effect of outputting each new character to the same location on the LCD.

  • Syntax
  • lcd.autoscroll()

  • Parameters
  • lcd: a variable of type LiquidCrystal
  • Similarly the function lcd.noautoscroll() stops the scrolling

  • leftToRight()
  • Description
  • Set the direction for text written to the LCD to left-to-right, the default. This means that subsequent characters written to the display will go from left to right, but does not affect previously-output text.

  • Syntax
  • lcd.leftToRight()

  • Parameters
  • lcd: a variable of type LiquidCrystal
  • Similarly there is a function lcd.rightTo Left() which works on the same parameters


  • createChar()
      Description
      Create a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are              supported (numbered 0 to 7). The appearance of each custom character is specified by an array of       eight bytes, one for each row. The five least significant bits of each byte determine the pixels in            that    row. To display a custom character on the screen, write() its number.

   NB : When referencing custom character "0", if it is not in a variable, you need to cast it as a byte,       otherwise the compiler throws an error. See the example below.

   Syntax
    lcd.createChar(num, data)

   Parameters
    lcd:     a variable of type LiquidCrystal
    num:   which character to create (0 to 7)
    data:   the character's pixel data

Feedback 

Please write in the comment if there is any problem with the code or with the material provided "I will be there to Happy To Help"





Comments

  1. Thanks for sharing such an amazing article, really informative

    Visit here : LCD Display Screen

    ReplyDelete
  2. youtube.com / video_dots_in
    youtube.com / video_dots_in. youtube.com / video_dots_in. youtube.com / video_dots_in. youtube.com / youtube to mp3 converter reviews video_dots_in. youtube.com / video_dots_in. youtube.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Distance on LCD display using Arduino and HC-SR04 Ultrasonic Sensor

Arduino with Speakers Project #01 a