How to use LCD on Arduino?

 You use an LCD on Arduino by doing two things:

  1. Wire it correctly

  2. Use the LiquidCrystal (or I2C) library in your sketch

I’ll show you both the classic 16×2 LCD with parallel pins and the I2C backpack version.




1. The LCD we’re talking about

Most tutorials (and this answer) assume a 16×2 character LCD that’s “HD44780-compatible”, like this:

  • 16 characters × 2 lines

  • Pins: VSS, VDD, VO, RS, RW, E, D0–D7, A, K

If yours has only 4 pins (GND, VCC, SDA, SCL) → that’s an I2C backpack version. I’ll cover that in section 4.


2. Wiring a 16×2 LCD directly to Arduino (4-bit mode)

We’ll use 4 data lines (D4–D7) to save pins.

Parts:

Typical wiring table (4-bit mode)

Assume these connections:

LCD PinNameConnect To
1VSSGND
2VDD+5V
3VOMiddle pin of 10k pot (contrast)
Pot side 1 → GND, side 2 → +5V
4RSArduino D12
5RWGND (we only write to LCD)
6EArduino D11
11D4Arduino D5
12D5Arduino D4
13D6Arduino D3
14D7Arduino D2
15A+5V through ~220 Ω (backlight +)
16KGND (backlight –)

(If numbering on your module is slightly different, just match by pin name.)


3. Basic Arduino code with LiquidCrystal

The Arduino IDE already has the LiquidCrystal library.

Example sketch: “Hello, world!”

#include <LiquidCrystal.h> // LiquidCrystal(rs, enable, d4, d5, d6, d7); LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { // Initialize 16 columns, 2 rows: lcd.begin(16, 2); lcd.print("Hello, world!"); delay(2000); lcd.clear(); lcd.setCursor(0, 0); // col 0, row 0 lcd.print("Line 1: Hi"); lcd.setCursor(0, 1); // col 0, row 1 lcd.print("Line 2: LCD :)"); } void loop() { // Optional: simple counter demo static int counter = 0; lcd.setCursor(10, 1); // print at end of second line lcd.print(counter); lcd.print(" "); // overwrite old digits counter++; delay(500); }

Upload this, then:

  • Adjust the contrast pot until you see characters clearly.

  • If nothing lights → check backlight connections (pins 15 & 16).

  • If boxes appear but no text → wiring or lcd.begin(16, 2) might be wrong.


4. Using an I2C LCD (backpack module)

If your LCD has a small board with 4 pins: GND, VCC, SDA, SCL:

Wiring:

For Arduino Uno / Nano:

  • GND → GND

  • VCC → 5V

  • SDA → A4

  • SCL → A5

(For other boards, SDA/SCL pins differ – check board pinout.)

Library

You’ll usually need a library like LiquidCrystal_I2C.

In Arduino IDE:

  1. Sketch → Include Library → Manage Libraries…

  2. Search for LiquidCrystal I2C

  3. Install something like LiquidCrystal I2C by Frank de Brabander (or similar)

Example sketch (I2C LCD):

#include <Wire.h> #include <LiquidCrystal_I2C.h> // Most modules use address 0x27 or 0x3F. // If text doesn’t appear, try the other address. LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); // Initialize the LCD lcd.backlight(); // Turn on backlight lcd.setCursor(0, 0); lcd.print("Hello I2C LCD!"); lcd.setCursor(0, 1); lcd.print("Arduino rocks!"); } void loop() { // simple blink text lcd.noBacklight(); delay(500); lcd.backlight(); delay(500); }

If nothing shows:

  • Try address 0x3F instead of 0x27.

  • Check wiring of SDA/SCL.


5. Handy tricks

  • Clear the display: lcd.clear();

  • Move cursor: lcd.setCursor(col, row);

  • Scroll text:

    lcd.scrollDisplayLeft(); lcd.scrollDisplayRight();
  • Custom characters: you can define your own icons with lcd.createChar() (using a 5×8 pixel pattern).

评论

此博客中的热门博文

Detailed Explanation of STM32 HAL Library Clock System

How do you set up ADC (Analog-to-Digital Converter) in STM32?

How To Connect Stm32 To PC?