A 16x2 LCD lets you show text on a small screen with 2 lines and 16 characters each. The LiquidCrystal library helps you easily control this screen from your Arduino.
You want to display sensor readings like temperature or humidity.
You want to show messages or instructions on a small device.
You want to debug your Arduino by showing variable values.
You want to create a simple user interface with menus.
You want to display time or status updates in a project.
Moves the cursor to the first column of the second line and prints text there.
Arduino
lcd.setCursor(0, 1);
lcd.print("Line 2 text");
Clears the screen before printing a new message.
Arduino
lcd.clear();
lcd.print("New message");
Sample Program
This program sets up the LCD and prints "Hello, Arduino!" on the first line. The screen stays showing this message.
Arduino
#include <LiquidCrystal.h>
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Hello, Arduino!"); // Print a message to the LCD
}
void loop() {
// Nothing to do here
}
OutputSuccess
Important Notes
Make sure your LCD is wired correctly to the Arduino pins you specify.
Use lcd.setCursor(col, row) to move where you print text.
Use lcd.clear() to erase the screen before printing new text.
Summary
The LiquidCrystal library controls 16x2 LCDs easily.
Initialize with pin numbers and call lcd.begin(16, 2).
Use lcd.print() to show text and lcd.setCursor() to move the cursor.
Practice
(1/5)
1. What does the lcd.begin(16, 2) command do in the LiquidCrystal library?
easy
A. It clears the LCD screen.
B. It sets up the LCD screen size to 16 columns and 2 rows.
C. It moves the cursor to the first position.
D. It prints text on the LCD screen.
Solution
Step 1: Understand lcd.begin() function
The lcd.begin() function initializes the LCD with the number of columns and rows.
Step 2: Apply to given parameters
Using lcd.begin(16, 2) sets the screen size to 16 columns and 2 rows.
Final Answer:
It sets up the LCD screen size to 16 columns and 2 rows. -> Option B
Quick Check:
lcd.begin(16, 2) = sets screen size [OK]
Hint: Remember lcd.begin sets screen size first [OK]
Common Mistakes:
Thinking lcd.begin clears the screen
Confusing lcd.begin with lcd.print
Assuming lcd.begin moves the cursor
2. Which of the following is the correct way to create a LiquidCrystal object for pins 12, 11, 5, 4, 3, 2?
easy
A. LiquidCrystal lcd = (12, 11, 5, 4, 3, 2);
B. LiquidCrystal lcd(2, 3, 4, 5, 11, 12);
C. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
D. LiquidCrystal lcd(12, 11, 5, 4);
Solution
Step 1: Recall LiquidCrystal constructor syntax
The constructor requires 6 pins: RS, Enable, D4, D5, D6, D7 in order.
Step 2: Match given pins to correct syntax
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); matches the correct order and number of pins.
Final Answer:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); -> Option C