How to Display Text on LCD Arduino: Simple Guide
To display text on an LCD with Arduino, use the
LiquidCrystal library. Initialize the LCD with the correct pins, then use lcd.print() to show your text on the screen.Syntax
First, include the LiquidCrystal library. Then create an lcd object with the pins connected to your LCD. Use lcd.begin(cols, rows) to set the screen size. Finally, use lcd.print() to display text.
LiquidCrystal(rs, enable, d4, d5, d6, d7): sets pinslcd.begin(cols, rows): sets LCD sizelcd.print(text): prints text on LCD
arduino
#include <LiquidCrystal.h> LiquidCrystal lcd(rs, enable, d4, d5, d6, d7); void setup() { lcd.begin(cols, rows); lcd.print("Your text here"); } void loop() { // your code }
Example
This example shows how to display "Hello, World!" on a 16x2 LCD connected to Arduino pins 12, 11, 5, 4, 3, and 2.
arduino
#include <LiquidCrystal.h> // Initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 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() { // Nothing needed here }
Output
Hello, World!
Common Pitfalls
Common mistakes include:
- Not initializing the LCD with
lcd.begin()before printing. - Using wrong pin numbers in the
LiquidCrystalconstructor. - Trying to print text before
setup()runs. - Not connecting the LCD's power or contrast pins properly.
Always check wiring and initialization order.
arduino
// Wrong: printing before begin #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { lcd.print("Oops!"); // Wrong: no lcd.begin() lcd.begin(16, 2); } void loop() {} // Right way: #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); lcd.print("Correct!"); } void loop() {}
Quick Reference
Remember these key steps:
- Include
LiquidCrystal.h - Initialize with correct pins
- Call
lcd.begin(cols, rows)insetup() - Use
lcd.print()to show text - Check wiring for power and contrast
Key Takeaways
Always initialize the LCD with lcd.begin() before printing text.
Use the LiquidCrystal library and specify correct Arduino pins.
lcd.print() shows text on the LCD screen.
Check your wiring carefully, especially power and contrast pins.
Print text only after setup() runs to avoid errors.