Table of Contents

Using LCD Display

An alphanumerical LCD is a straightforward and widely used output device in embedded systems and IoT applications. The LCD used here has a fixed organization of 2 lines and 16 characters per line (2×16).

This scenario guides you through displaying text on the LCD using Arduino.

Prerequisites

Hardware Connections

LCD Pin Arduino Pin
—————————-
RS 8
EN 9
D4 4
D5 5
D6 6
D7 7
Buttons Input A0

Suggested Knowledge Resources

Task

Display the text “Hello World” on the first line and “Hello IoT” on the second line of the LCD.

Steps

Step 1: Include Library

Add the LCD library to your Arduino sketch:

#include <LiquidCrystal.h>

Step 2: Declare GPIO Pins

Define GPIO pins connected to LCD control lines:

const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;

Step 3: Initialize LCD

Create an instance of the LCD:

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Set up the display dimensions (2 rows, 16 columns):

lcd.begin(16, 2);

Step 4: Display Text

Write text to the LCD screen:

lcd.setCursor(0, 0); // top left corner
lcd.print("Hello World");
 
lcd.setCursor(0, 1); // second line
lcd.print("Hello IoT");

Validation

The LCD should clearly display “Hello World” on line 1 and “Hello IoT” on line 2.

Useful Methods

Troubleshooting

If the LCD shows incorrect characters or nothing:

  1. Double-check wiring and pin assignments.
  2. Verify correct initialization (`lcd.begin(16,2)`).
  3. Adjust the contrast potentiometer on the LCD, if available.