16×2 LCD Interface – Arduino LCD Display

There are various kind of displays available for Arduino boards. Some of them use I2C communication, some use SPI protocol and some uses port interface. Liquid Crystal or LCD displays are available in two sizes, 16×2 LCD( 16 Column, 2 Row) and 20×4 LCD( 20 Column, 4 Row). Both of them can be used using the same Arduino library called “LiquidCrystal.h“.

Connect 16×2 LCD Display With Arduino

16x2 LCD Arduino Interface

LCD Displays have a drawback and that is, it used too much of the pins to be operated. It need at least 6 pins of the Arduino for 4-bit communication and 10 pins for 8-bit communication. But they are used on most of the projects because coding them is easier.

 

Arduino code for a LCD Display

First of all, define the pins and create an lcd object. Inside the void setup, “lcd.begin(16, 2) stands for 16×2 LCD display that has 16 columns and 2 rows. In case of 20×4 LCD display, lcd.begin(20,4) it will be. Any string of 16 characters can be printed using lcd.print() function. Other data types can also be used by simply passing them into the function.

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

lcd.setCursor() is used to print data in a particular location into the display. If you want to display a message into 2nd row, column 5 then the code will be lcd.setCursor(4,1). The prototype of the function is lcd.setCursor(column, row). The numbering starts from 0. So, for 2nd row, it will be 1 and 5th column, it will be 4.

Leave a Reply

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