I2C LCD1602

Overview

In this lesson, you will learn about Liquid Crystal Displays (LCDs) with an I2C interface. These types of LCDs are widely used in a variety of electronic devices, such as digital clocks, microwave ovens, car dashboards, and even industrial equipment. The I2C interface simplifies the wiring and connections, making it more convenient and efficient for hobbyists and professionals alike.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Elite Explorer Kit

300+

Elite Explorer Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

Arduino Uno R4 WiFi

-

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

I2C LCD1602

BUY

Wiring

../_images/14-i2c_lcd_bb.png

Schematic Diagram

../_images/14-i2c_lcd_schematic.png

Code

Note

  • You can open the file 14-i2c_lcd.ino under the path of elite-explorer-kit-main\basic_project\14-i2c_lcd directly.

  • Or copy this code into Arduino IDE.

Note

To install the library, use the Arduino Library Manager and search for “LiquidCrystal I2C” and install it.

After the code is uploaded successfully to the Arduino, the Liquid Crystal Display (LCD) will show the message “Hello world!” on its first line and “LCD Tutorial” on its second line.

Note

If the LCD does not display any characters after uploading the code, you can adjust the contrast by rotating the potentiometer on the I2C module until the LCD functions correctly.



Code Analysis

  1. Library Inclusion and LCD Initialization: The LiquidCrystal I2C library is included to provide functions and methods for LCD interfacing. Following that, an LCD object is created using the LiquidCrystal_I2C class, specifying the I2C address, number of columns, and number of rows.

    Note

    To install the library, use the Arduino Library Manager and search for “LiquidCrystal I2C” and install it.

    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    
  2. Setup Function: The setup() function is executed once when the Arduino starts. In this function, the LCD is initialized, cleared, and the backlight is turned on. Then, two messages are displayed on the LCD.

    void setup() {
      lcd.init();       // initialize the LCD
      lcd.clear();      // clear the LCD display
      lcd.backlight();  // Make sure backlight is on
    
      // Print a message on both lines of the LCD.
      lcd.setCursor(2, 0);  //Set cursor to character 2 on line 0
      lcd.print("Hello world!");
    
      lcd.setCursor(2, 1);  //Move cursor to character 2 on line 1
      lcd.print("LCD Tutorial");
    }