How to connect LCD to Arduino?


Connecting an LCD (Liquid Crystal Display) to an Arduino is a fundamental skill. The most common type is the 16x2 Character LCD (16 columns, 2 rows), which can be connected in two main ways: the "standard" method using many wires, or the easier "I2C" method.
Method 1: Using an I2C Module (The Highly Recommended, Easy Way)
This method uses a small adapter that sits on the back of the LCD and requires only 4 wires. It's much simpler and saves precious GPIO pins.
What You Need:
Arduino Uno (or any other Arduino)
16x2 LCD Screen
I2C LCD Adapter Module (e.g., PCF8574 or similar)
Potentiometer (optional, for contrast adjustment if your I2C module doesn't have one)
Connection Steps (Wiring):
The I2C module has 4 pins:
GND -> Arduino GND
VCC -> Arduino 5V
SDA -> Arduino A4 (or the dedicated SDA pin on newer boards)
SCL -> Arduino A5 (or the dedicated SCL pin on newer boards)
Wiring Diagram:
text
LCD I2C Module -> Arduino Uno
GND -> GND
VCC -> 5V
SDA -> A4 (SDA)
SCL -> A5 (SCL)
Code Steps (Software):
Find the I2C Address: The I2C module has a unique address that you need for your code. You can find it by running an I2C scanner sketch. A common default address is
0x27
or0x3F
.Install the Library: In the Arduino IDE, go to Sketch > Include Library > Manage Libraries.... Search for and install "LiquidCrystal I2C" by Frank de Brabander.
Upload the Example Code:
cpp
// Include the required library
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16x2 display
// If 0x27 doesn't work, try 0x3F
LiquidCrystal_I2C lcd(0x27, 16, 2); // (Address, Columns, Rows)
void setup() {
// Initialize the LCD
lcd.init();
// Turn on the backlight
lcd.backlight();
// Print a message to the LCD.
lcd.print("Hello, World!");
}
void loop() {
// Set the cursor to column 0, line 1 (second row)
lcd.setCursor(0, 1);
// Print the number of seconds since reset
lcd.print(millis() / 1000);
lcd.print(" seconds");
}
Method 2: Direct Connection (The "Standard" 16-pin Way)
This method connects the LCD directly to the Arduino using many digital pins. It's good to understand how it works but uses more wires.
What You Need:
Arduino Uno
16x2 LCD Screen
Potentiometer (e.g., 10kΩ) for contrast adjustment
Jumper wires
Breadboard (highly recommended)
Connection Steps (Wiring):
The LCD has 16 pins. The key ones are:
LCD Pin | Name | Function | Connects to... |
1 | VSS | Ground | Arduino GND |
2 | VDD | Power | Arduino 5V |
3 | V0 | Contrast | Potentiometer middle pin |
4 | RS | Register Select | Digital Pin 12 |
5 | RW | Read/Write | Arduino GND (puts LCD in write mode) |
6 | E | Enable | Digital Pin 11 |
7-10 | D0-D3 | Data Bits 0-3 | Not Connected (we use 4-bit mode) |
11-14 | D4-D7 | Data Bits 4-7 | Pins 5, 4, 3, 2 |
15 | A | LED Backlight (+) | Arduino 5V (through a 220Ω resistor) |
16 | K | LED Backlight (-) | Arduino GND |
How to connect the potentiometer for contrast:
Connect one outer pin to Arduino 5V.
Connect the other outer pin to Arduino GND.
Connect the middle pin to LCD Pin 3 (V0).
Wiring Diagram (Simplified View):
text
LCD -> Arduino
RS -> Pin 12
E -> Pin 11
D4 -> Pin 5
D5 -> Pin 4
D6 -> Pin 3
D7 -> Pin 2
VSS -> GND
VDD -> 5V
V0 -> Potentiometer Middle Pin
RW -> GND
A -> 5V (via resistor)
K -> GND
Code Steps (Software):
Use the Built-in Library: The Arduino IDE comes with the necessary library.
Upload the Code:
cpp
// Include the LiquidCrystal library
#include <LiquidCrystal.h>
// Initialize the library with the pin numbers
// (RS, E, D4, D5, D6, D7)
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() {
// Set the cursor to column 0, line 1 (second row)
lcd.setCursor(0, 1);
// Print the number of seconds since reset
lcd.print(millis() / 1000);
lcd.print(" seconds");
}
Troubleshooting Common Issues
Blank Screen / No Text: This is almost always a contrast issue. Adjust the potentiometer connected to Pin 3 (V0) until the text appears. This is the most common fix.
Garbled Text:
Check your wiring. Loose connections on the data pins (D4-D7) are the most likely cause.
Ensure the RW pin (Pin 5) is connected to GND.
I2C LCD Doesn't Work:
You have the wrong I2C address. Run an I2C scanner sketch to find the correct address for your module.
Double-check the SDA and SCL connections.
Recommendation: For beginners and most projects, use the I2C method. It is significantly easier to wire and troubleshoot, leaving you with more pins for sensors and motors.
Subscribe to my newsletter
Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
