กลับหน้าหลัก
views
How to Use ESP32 with LCD 1602 Display via I2C
Last updated on

How to Use ESP32 with LCD 1602 Display via I2C


How to Use ESP32 with LCD 1602 Display via I2C

This tutorial shows you how to connect an ESP32 board to a 1602 LCD display using the I2C interface. You’ll learn the wiring, library installation, and how to write code that displays text on the screen.

Required Components

  • ESP32 NodeMCU board (ESP-WROOM-32)
  • LCD 1602 with I2C Interface module
  • Breadboard
  • Male-to-female jumper wires
  • Micro USB cable for computer connection

ESP32 to LCD 1602 Wiring

The I2C interface only needs 4 wires, which saves many GPIO pins on the ESP32.

Diagram showing ESP32 board connected to LCD 1602 I2C module on a breadboard with labeled pins
ESP32LCD 1602 I2C
VIN (5V)VCC
GNDGND
D21SDA
D22SCL

The VIN pin on ESP32 supplies 5V to power the LCD. If your ESP32 board doesn’t have a VIN pin, use the 5V pin instead.

Installing LiquidCrystal_I2C Library

  1. Download the library from https://github.com/marcoschwartz/LiquidCrystal_I2C
  2. Extract the files and move the LiquidCrystal_I2C folder to Documents/Arduino/libraries/
  3. Close and reopen Arduino IDE
Arduino IDE window showing successful library installation at Tools > Manage Libraries

Example Code to Display Text on LCD

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set LCD address - if screen doesn't work, try 0x3F instead of 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.begin();
  lcd.backlight();

  // Print on first row
  lcd.setCursor(0, 0);
  lcd.print("ESP32 + LCD 1602");

  // Print on second row
  lcd.setCursor(0, 1);
  lcd.print("Hello World!");
}

void loop() {
  // Nothing to do here
}

Adjustable points: If the display shows nothing, try changing the address from 0x27 to 0x3F because different LCD modules may use different I2C addresses.

How to Upload Code to ESP32

  1. Open the code in Arduino IDE and select Board as ESP32 Dev Module
  2. Choose the correct Port that matches your board
  3. Click the Upload button
  4. If a dialog asks to save the sketch, just click Cancel
Arduino IDE window showing Done Uploading status at the bottom

When upload gets stuck: If the “Connecting…” message appears for more than 5 seconds, press and hold the BOOT button on the ESP32 board until the upload finishes.

Common LiquidCrystal_I2C Commands

CommandFunction
lcd.begin(16, 2)Initialize display 16 chars, 2 rows
lcd.backlight()Turn on LCD backlight
lcd.noBacklight()Turn off LCD backlight
lcd.setCursor(col, row)Set cursor position
lcd.print("text")Print text to display
lcd.clear()Clear the display

Reference Video

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ความคิดเห็น

Verified user reviews

รีวิวและความคิดเห็นจากผู้ใช้จริง

ล็อกอินด้วยบัญชีบนเว็บนี้แล้วให้คะแนนหรือคอมเมนต์ได้เลย ระบบเก็บผ่าน Supabase ไม่ต้องใช้ GitHub แล้ว

กำลังโหลดรีวิว...