Home ArduinoArduino Code Arduino and I2C 1602 Serial LCD example

Arduino and I2C 1602 Serial LCD example

In this example we connect a 16×2 LCD with an I2C backpack, this backpack allows us to only use 2 pins to connect our LCD to an Arduino, so if you are limited with regards to the amount of I/O you have available then this can be an ideal solution because this LCD uses an I2C module other than VCC and GND the only 2 connections you need are SDA and SCL which are A4 and A5.

Here is  a typical example of this LCD and the I2C module which is fitted to it, this is the LCD I use in this example

lcd i2c 1602

lcd i2c 1602

Here is a schematic showing how to connect the LCD up

arduino and i2c lcd

arduino and i2c lcd

Code

This uses the http://www.dfrobot.com/image/data/DFR0154/LiquidCrystal_I2Cv1-1.rar, download, extract and copy to your libraries folder as usual

We will simply display hello world on the LCD, watch the address below if you buy this from a different manufacturer as it can be different, use th I2C scanner link in the comments to detect the I2C address.

[codesyntax lang=”cpp”]

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
 
//use the i2c scanner at http://playground.arduino.cc/Main/I2cScanner?action=sourceblock&num=1
//to get the address below
LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x3f for a 16 chars and 2 line display
 
void setup()
{
  lcd.init();// initialize the lcd 
  
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello world");
}
 
void loop()
{
}

[/codesyntax]

 

Links

SainSmart IIC/I2C/TWI 1602 Serial LCD Module Display for Arduino UNO MEGA R3 *Blue on White*

You may also like