How to use LCD on Arduino?
You use an LCD on Arduino by doing two things:
-
Wire it correctly
-
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:
-
Arduino Uno (any board is fine)
-
16×2 LCD
-
10 kΩ potentiometer (for contrast)
-
Some jumper wires
-
Optional: 220 Ω resistor for LCD backlight
Typical wiring table (4-bit mode)
Assume these connections:
| LCD Pin | Name | Connect To |
|---|---|---|
| 1 | VSS | GND |
| 2 | VDD | +5V |
| 3 | VO | Middle pin of 10k pot (contrast) |
| Pot side 1 → GND, side 2 → +5V | ||
| 4 | RS | Arduino D12 |
| 5 | RW | GND (we only write to LCD) |
| 6 | E | Arduino D11 |
| 11 | D4 | Arduino D5 |
| 12 | D5 | Arduino D4 |
| 13 | D6 | Arduino D3 |
| 14 | D7 | Arduino D2 |
| 15 | A | +5V through ~220 Ω (backlight +) |
| 16 | K | GND (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!”
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:
-
Sketch → Include Library → Manage Libraries…
-
Search for
LiquidCrystal I2C -
Install something like
LiquidCrystal I2C by Frank de Brabander(or similar)
Example sketch (I2C LCD):
If nothing shows:
-
Try address
0x3Finstead of0x27. -
Check wiring of SDA/SCL.
5. Handy tricks
-
Clear the display:
lcd.clear(); -
Move cursor:
lcd.setCursor(col, row); -
Scroll text:
-
Custom characters: you can define your own icons with
lcd.createChar()(using a 5×8 pixel pattern).
.jpg)
评论
发表评论