How To interface an I2C module with an LCD and print “Hello World” using an Arduino Uno

Components Needed:

  1. Arduino Uno board
  2. 16×2 LCD display with I2C module
  3. Jumper wires

Wiring:

  • I2C LCD Pin Connections:
    • VCC of the I2C module to 5V on the Arduino
    • GND of the I2C module to GND on the Arduino
    • SDA of the I2C module to A4 on the Arduino (SDA pin)
    • SCL of the I2C module to A5 on the Arduino (SCL pin)

Code:

Here’s how you can write the code to print “Hello World” on the LCD:

  1. Install the LiquidCrystal_I2C Library:
    • Open the Arduino IDE.
    • Go to Sketch > Include Library > Manage Libraries.
    • In the Library Manager, search for LiquidCrystal_I2C and install it.

2. Arduino Code:

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

LiquidCrystal_I2C lcd(0x27, 16, 2); 

void setup() {
  lcd.begin(16, 2);         
  lcd.backlight();    
  lcd.setCursor(0, 0);    
  lcd.print("Hello World!");    
}

void loop() {

 }

Steps to Run the Code:

  1. Connect the Components:
    • Connect the I2C LCD to the Arduino as described above.
  2. Upload the Code:
    • Open the Arduino IDE.
    • Select the correct board (Arduino Uno) and port in the Tools menu.
    • Paste the code above into the IDE and upload it to your Arduino.
  3. Power On:
    • Once uploaded, your LCD should display “Hello World!” on the screen.

Troubleshooting Tips:

  • If the LCD doesn’t display anything, ensure the I2C address is correct (common addresses are 0x27 or 0x3F). If the address is different, you can use the I2C Scanner code to find the correct address.
  • If the display shows strange characters, try adjusting the contrast using the potentiometer on the I2C module.
  • Double-check your wiring connections for any loose connections.

That’s it! You have successfully interfaced an I2C LCD with an Arduino and printed “Hello World”.

Leave a Comment