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.
LCD Pin | Arduino Pin |
————— | ————- |
RS | 8 |
EN | 9 |
D4 | 4 |
D5 | 5 |
D6 | 6 |
D7 | 7 |
Buttons Input | A0 |
Display the text “Hello World” on the first line and “Hello IoT” on the second line of the LCD.
Add the LCD library to your Arduino sketch:
#include <LiquidCrystal.h>
Define GPIO pins connected to LCD control lines:
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
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);
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");
The LCD should clearly display “Hello World” on line 1 and “Hello IoT” on line 2.
lcd.clear()
– clears all text from the LCD.lcd.setCursor(col, row)
– positions the cursor.lcd.print(data)
– prints data to the display.If the LCD shows incorrect characters or nothing: