The 16x2 LCD with I2C interface is a great option for reducing the number of pins needed to control a standard 16x2 character LCD, making it a popular choice for Arduino and Raspberry Pi projects. With the I2C interface, you can control the LCD using only two data pins, which simplifies wiring and saves microcontroller I/O pins for other tasks.
I2C (Inter-Integrated Circuit) is a communication protocol that allows multiple devices (e.g., sensors, displays, EEPROMs) to communicate with a microcontroller using only two wires:
With I2C, devices are addressed using a 7-bit address. Multiple I2C devices can share the same bus, and each device is uniquely identified by its address.
Here’s a quick overview of the pins on the 16x2 LCD with I2C module:
PinFunctionDescription1GNDGround pin2VCCPower pin (typically 5V or 3.3V depending on your system)3SDAData line (connected to the SDA pin on your microcontroller)4SCLClock line (connected to the SCL pin on your microcontroller)5AAnode pin for backlight (optional for some models)6KCathode pin for backlight (optional for some models)
The I2C address of the LCD module is usually one of the following:
If your LCD isn't working with one address, try the other.
You can find the I2C address of your module using an I2C scanner sketch (especially if you're unsure about the address).
Here’s a simple guide for wiring the 16x2 LCD with I2C to an Arduino:
To control the LCD, you will need the LiquidCrystal_I2C library. It simplifies the communication between the Arduino and the I2C LCD.
Alternatively, you can manually download the library from GitHub LiquidCrystal_I2C on GitHub.
Here’s an example code to display "Hello, World!" on the 16x2 LCD with I2C:
#include <Wire.h> // Include the Wire library for I2C communication #include <LiquidCrystal_I2C.h> // Include the LiquidCrystal_I2C library // Initialize the LCD with I2C address 0x3F, 16 columns, and 2 rows LiquidCrystal_I2C lcd(0x3F, 16, 2); void setup() { lcd.begin(); // Initialize the LCD lcd.backlight(); // Turn on the backlight (optional) lcd.setCursor(0, 0); // Set cursor to the first column, first row lcd.print("Hello, World!"); // Display message on the screen } void loop() { // No code needed in loop for static text }
Wire.begin()
: Initializes I2C communication.lcd.begin()
: Initializes the LCD. In this case, lcd(0x3F, 16, 2)
tells the Arduino that the LCD is connected with address 0x3F
, and it has 16 columns and 2 rows.lcd.setCursor(x, y)
: Sets the position of the cursor (x = column, y = row). The position is 0-indexed, so setCursor(0, 0)
places the cursor at the top-left corner.lcd.print("Hello, World!")
: Prints the message to the LCD at the current cursor position.If the display is too faint or not visible, adjust the contrast by turning the small potentiometer (usually located on the back of the I2C module). This allows you to adjust the voltage going to the V0 pin, which controls the contrast.
If you're unsure about the I2C address of your LCD module, you can upload the following I2C Scanner sketch to your Arduino to detect the address:
#include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); Serial.println("\nI2C Scanner"); for (byte address = 1; address < 127; address++) { Wire.beginTransmission(address); byte error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) { Serial.print("0"); } Serial.println(address, HEX); } delay(100); } } void loop() { // Empty loop }
Upload this code to your Arduino, and open the Serial Monitor. It will scan all I2C addresses from 0x01
to 0x7F
, and it will print the address of any I2C devices it finds, including your LCD.
Brand:- Generic
Origin:- China