How to connect LCD to Arduino?

ampheoampheo
4 min read

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.


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:

Connection Steps (Wiring):

The I2C module has 4 pins:

  1. GND -> Arduino GND

  2. VCC -> Arduino 5V

  3. SDA -> Arduino A4 (or the dedicated SDA pin on newer boards)

  4. 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):

  1. 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 or 0x3F.

  2. Install the Library: In the Arduino IDE, go to Sketch > Include Library > Manage Libraries.... Search for and install "LiquidCrystal I2C" by Frank de Brabander.

  3. 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 PinNameFunctionConnects to...
1VSSGroundArduino GND
2VDDPowerArduino 5V
3V0ContrastPotentiometer middle pin
4RSRegister SelectDigital Pin 12
5RWRead/WriteArduino GND (puts LCD in write mode)
6EEnableDigital Pin 11
7-10D0-D3Data Bits 0-3Not Connected (we use 4-bit mode)
11-14D4-D7Data Bits 4-7Pins 5, 4, 3, 2
15ALED Backlight (+)Arduino 5V (through a 220Ω resistor)
16KLED 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):

  1. Use the Built-in Library: The Arduino IDE comes with the necessary library.

  2. 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.

0
Subscribe to my newsletter

Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ampheo
ampheo