The 1602 LCD display is a widely used alphanumeric display that consists of two lines, each capable of displaying 16 characters. Its versatility makes it suitable for various applications, including vending machines and train stations. While it is commonly included in Arduino kits, the instructions provided here can be applied to any LCD display that has a 16-pin interface compatible with the Hitachi HD44780 LCD controller.
To control the display, the LiquidCrystal Arduino library emulates the Hitachi HD44780 LCD controller. In this blog post, we will explore the simplest way to use the display by printing the famous “Hello, World!” message.
The LCD display has 16 input pins, which are as follows:
VSS
: the negative connectionVDD
: the positive connectionVO
: adjusts the contrast (connected to a potentiometer in our project)RS
: connected to pin 7 of the ArduinoR/W
: connected to ground (-
) to set the LCD in “write mode”E
: connected to pin 8 of the ArduinoD0-D7
: the data pins. In this example, we will only useD4
,D5
,D6
, andD7
A
andK
: control the LED backlight. ConnectA
to the positive terminal via a 220Ω resistor, andK
to the negative terminal.
To print the “Hello, World!” message, we can use the following Arduino code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
lcd.begin(16, 2);
lcd.print("Hello,");
lcd.setCursor(0, 1);
lcd.print("World!");
}
void loop() {
}
In this code, we first configure the lcd
object by specifying the pin numbers for RS
, R/W
, E
, D4
, D5
, D6
, and D7
. Then, we call the lcd.begin()
method, passing the number of columns and rows of the LCD display.
By using the lcd.print()
method, we can print a string on the display starting at position (0, 0)
. To move the cursor, we can use the lcd.setCursor()
method, specifying the column and row indexes.
To build the circuit, follow the schematic shown below:
And here’s an example of a real-world implementation:
You can adjust the contrast of the display by trimming the potentiometer. Once you find your preferred setting, you can replace the potentiometer with a resistor to maintain the desired contrast.