In this post we shall see how to interface a 16/2 LCD with Arduino.16/2 LCD is capable of displaying
16 characters per Row(Line) & has 2 Rows.
Other types available are 16 x 1 , 16 x 4 , 20 x 4 & Graphical LCDs.Most of these LCDs are with
Back light option (either Blue or Green).
For connectivity to a Bread board use a Berg Stick. Solder 16 pins of Berg stick to LCD so that it can
be easily plugged on to a Bread Board.
Connection details of 16/2 LCD :
1. Pins 1& 16 are GND pins.
2. 2nd & 15th pins are power supply pins.15th pin is supply pin for Back light.
3. 3rd pin is Contrast pin.This is connected to center pin of a 10k potentiometer to vary the contrast.
4. 4th pin is RS.(Register Select). LCDs have 2 Registers,a Data Register & a Command Register.
Data Register holds what goes on to the LCD screen.The Command Register holds the Instructions
& the LCDs controller looks here for what to do next..RS = 1 means Data Input.
5. The 5th pin is RW –Read/Write pin.A Low on this pin means Write mode & High to this pin means
Read mode.As we use the LCD to display message (WRITE mode),generally 5th pin is connected
to GND .i.e.. made Low. RW = 0 means LCD in Write mode
6. The 6th pin is Enable pin, which enables writing to Registers.The EN pin is used to tell the LCD when data is ready for reading.
The three control lines that control the LCD are EN, RS, and RW.
The EN “Enable” control line is used to tell the LCD that you are sending in data.
To send data to the LCD, your program should make sure this line is low (0) and then set the other two control lines and put data on the data bus. When the other lines are completely ready, bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet , and end by bringing it low (0) again.
The RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data being sent is text data which should be displayed on the screen.
The RW line is the “Read/Write” control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only one instruction (“Get LCD status”) is a read command. All others are write commands–so RW will almost always be low.
7. LCDs can be controlled in 2 modes – 4 bit or 8 bit. 4 bit mode requires 7 I/O pins from Arduino & 8 bit mode requires 11 pins.
For displaying text on screen 4 bit mode can do the most everything.Data pins D4,D5,D6 & D7 are used for 4 bit mode.(pins 11,12,13 &14)
Connecting Arduino to LCD :
1. Connect GND of Arduino to Bread board’s Negative rail & 5V of Arduino to +ve Rail.
2. Connect 1 & 16 pins of LCD to –ve Row (GND).
3. Connect 2nd & 15th pins of LCD to +ve Row.(5v supply from Arduino).
4.Use a 10k potentiometer for Contrast control.Connect first pin of potentiometer to
+ve rail & the last pin to – ve rail of breadboard.Now connect the center pin of potentiometer
to 3rd pin of LCD.
5. Connect 4th pin of LCD (Register Select) to Digital pin 2 of Arduino.
6. Connect 5th pin RS of LCD to GND to make LCD work in Write mode.
7. Connect 6th pin Enable of LCD to digital pin 4 of Arduino.
8. Connect Data pins 11,12,13,& 14 of LCD TO DIGITAL PINS 8,9,10 & 11 of Arduino.
9.Fire up the Arduino IDE & Open Up Files –> Examples->Liquid Crystal
Change the code LiquidCrystal lcd(12,11,5,4,3,2);
to LiquidCrystal lcd(2,4,8,9,10,11);
Here we create a variable called lcd for our display & tell the sketch which pins are connected to which Digital output pins.This is done with above Function
Here pin 2 is the RS & pin 4 is Enable ,pins 8,9,10,11 are 4bit Data.
The Arduino pins we use to control LCD is defined in code as above.
In void setup() , add the line lcd.begin(16,2) which tells the sketch the dimension in characters(columns,rows) of our LCD module defined as variable lcd.
Now the final code to Upload looks like :
//code to display “Hello world” on LCD
# include <LiquidCrystal.h> /* LCD Library code is included.The
library comes preinstalled with IDE*/
LiquidCrystal lcd(2,4,8,9,10,11); /*Library is initialized with numbers of interface pins*/
lcd.begin(16,2); /* a variable of type LiquidCrystal lcd initialized
with 16 columns,2 rows */
lcd.print(“Hello world..!); // character data to be printed on LCD
lcd.setCursor(0,1); /* move cursor to first column(0 is the first column) & second row
(0 is first Row, 1 is second Row) */
lcd.print(millis()/1000); /* Displays no. of milliseconds since the Arduino board began running
the current program.It will go back to 0 after 50 days!!! */
Upload the above code on to Arduino board & see the result on the LCD display.
Some other interesting Functions of LCD library are :
lcd.scrollDisplayLeft() -> Scrolls the contents of display one space to left.
lcd.blink() -> Display the blinking LCD cursor
lcd.noBlink() -> Turn off the blinking cursor.
lcd.home() -> go to position (0,0)
lcd.clear() -> Clears the display
//code to scroll the display left
For further examples visit the Arduino official website here
Watch this Demo video :