Hello World!
" Code
The process of controlling the display involves /*
putting the data that form the image of what you LiquidCrystal Library - Hello World
want to display into the data registers, then putting
instructions in the instruction register. Demonstrates the use a 16x2 LCD display.
The LiquidCrystal Library simplifies this for you so The LiquidCrystal
you don't need to know the low-level instructions. library works with all LCD displays that are
The Hitachi-compatible LCDs can be controlled in two compatible with the
modes: 4-bit or 8-bit. The 4-bit mode requires seven Hitachi HD44780 driver. There are many of
I/O pins from the Arduino, while the 8-bit mode them out there, and you
requires 11 pins. For displaying text on the screen, can usually tell them by the 16-pin
you can do most everything in 4-bit mode, so interface.
example shows how to control a 2x16 LCD in 4-bit
mode. This sketch prints "Hello World!" to the LCD
and shows the time.
Hardware Required
Arduino or Genuino Board The circuit:
LCD Screen (compatible with Hitachi HD44780 driver) * LCD RS pin to digital pin 12
pin headers to solder to the LCD display pins * LCD Enable pin to digital pin 11
10k ohm potentiometer * LCD D4 pin to digital pin 5
220 ohm resistor * LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
hook-up wires
* LCD D7 pin to digital pin 2
breadboard * LCD R/W pin to ground
Circuit * LCD VSS pin to ground
Before wiring the LCD screen to your Arduino or * LCD VCC pin to 5V
Genuino board we suggest to solder a pin header * 10K resistor:
strip to the 14 (or 16) pin count connector of the LCD * ends to +5V and ground
screen, as you can see in the image above. * wiper to LCD VO pin (pin 3)
To wire your LCD screen to your board, connect the
following pins: */
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11 // include the library code:
LCD D4 pin to digital pin 5 #include <LiquidCrystal.h>
LCD D5 pin to digital pin 4
// initialize the library by associating any
LCD D6 pin to digital pin 3 needed LCD interface pin
LCD D7 pin to digital pin 2 // with the arduino pin number it is
Additionally, wire a 10k pot to +5V and GND, with it's connected to
wiper (output) to LCD screens VO pin (pin3). A 220 const int rs = 12, en = 11, d4 = 5, d5 = 4, d
ohm resistor is used to power the backlight of the 6 = 3, d7 = 2;
display, usually on pin 15 and 16 of the LCD LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
connector
void setup() {
// set up the LCD's number of columns and
rows:
[Link](16, 2);
// Print a message to the LCD.
[Link]("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
Schematic // (note: line 1 is the second row, since
counting begins with 0):
[Link](0, 1);
// print the number of seconds since reset:
[Link](millis() / 1000);
}