
1. Introduction
The Raspberry Pi is a powerful mini-computer widely used for IoT, automation, and embedded projects. Interfacing a 16x2 LCD with Raspberry Pi GPIO allows you to display messages, system status, sensor values, and more.
In this guide, you will learn how to connect and control a 16x2 LCD using Raspberry Pi GPIO in 4-bit mode.
2. Components
- Raspberry Pi 4 Model B (or any Raspberry Pi)
- 16x2 LCD Display
- 10K Potentiometer
- Breadboard
- Jumper wires
- Power supply
3. Circuit and Connections
| Pin-out Diagram 16X2 LCD |
GPIO to LCD Connection (4-bit mode)
| LCD Pin | Name | Raspberry Pi GPIO |
|---|---|---|
| 1 | VSS | GND |
| 2 | VDD | 5V |
| 3 | V0 | Potentiometer middle pin |
| 4 | RS | GPIO25 |
| 5 | RW | GND |
| 6 | EN | GPIO24 |
| 11 | D4 | GPIO23 |
| 12 | D5 | GPIO17 |
| 13 | D6 | GPIO18 |
| 14 | D7 | GPIO22 |
| 15 | LED+ | 5V |
| 16 | LED- | GND |
4. Detailed Step By Step Circuit Working
- Raspberry Pi supplies 5V and GND to the LCD.
- The potentiometer controls display contrast.
- GPIO pins send control signals (RS, EN).
- Data is transmitted in 4-bit mode (D4–D7).
- LCD receives commands and displays characters accordingly.
5. Libraries to be Included
Install GPIO library:
pip install RPLCD
pip install RPi.GPIO
6. Code (Python)
from RPLCD.gpio import CharLCD
import RPi.GPIO as GPIO
from time import sleep
lcd = CharLCD(
numbering_mode=GPIO.BCM,
cols=16, rows=2,
pin_rs=25,
pin_e=24,
pins_data=[23, 17, 18, 22]
)
lcd.write_string("Hello!")
sleep(2)
lcd.clear()
lcd.write_string("Raspberry Pi LCD")
7. Detailed Step By Step Code Working
CharLCD(...)→ Initializes LCD with GPIO pinsnumbering_mode=GPIO.BCM→ Uses BCM pin numberinglcd.write_string()→ Displays textlcd.clear()→ Clears displaysleep()→ Adds delay
8. Tips
- Use BCM pin numbering consistently
- Ensure proper contrast adjustment
- Use external power if LCD backlight is dim
- Double-check wiring before powering ON
- Prefer I2C LCD module to reduce wiring complexity
9. Uses
- IoT dashboards
- System monitoring (CPU temp, IP address)
- Home automation display panels
- Robotics status display
- Industrial monitoring systems
10. Conclusion
Interfacing a 16x2 LCD with Raspberry Pi is a simple yet powerful way to add a visual output to your projects. With Python libraries, controlling the LCD becomes very easy and efficient.