Lesson 9: LCD Display with I2C

 

Lesson 9: LCD Display with I2C

Lesson: LCD Display with I2C

Objective: At the end of this lesson, you will be able to display text on a 16x2 LCD using Arduino with I2C communication.

Materials Required:

  • Arduino board
  • 16x2 LCD display module with I2C backpack
  • Jumper wires
  • USB cable

Circuit Connections:

  1. Connect the SDA pin on the LCD module to the SDA pin on the Arduino board.
  2. Connect the SCL pin on the LCD module to the SCL pin on the Arduino board.
  3. Connect the VCC pin on the LCD module to the 5V pin on the Arduino board.
  4. Connect the GND pin on the LCD module to the ground (GND) pin on the Arduino board.


Arduino Code:

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

LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address and LCD dimensions

void setup() {
  lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  lcd.print("Hello, World!"); // Display text on the LCD
}

void loop() {
  // No actions required in the loop
}

Experiment Steps:

  1. Set up the circuit connections as described above.
  2. Connect the Arduino board to your computer using a USB cable.
  3. Open the Arduino IDE software and create a new sketch.
  4. Install the "LiquidCrystal_I2C" library by going to "Sketch" -> "Include Library" -> "Manage Libraries" and searching for "LiquidCrystal_I2C". Click "Install" to install the library.
  5. Copy and paste the provided code into the Arduino IDE.
  6. Click the "Upload" button to upload the code to the Arduino board.
  7. Observe the text "Hello, World!" displayed on the LCD module.
  8. Experiment with modifying the displayed text and LCD settings to customize the output.

Explanation: In this experiment, we are using the LiquidCrystal_I2C library to control a 16x2 LCD display with an I2C backpack connected to the Arduino board. The I2C backpack simplifies the wiring by allowing communication over the I2C bus.

The setup() function is used for the initialization of the LCD. We create an object of the LiquidCrystal_I2C class called lcd and pass the I2C address of the LCD module (0x27) and the dimensions of the LCD (16 columns and 2 rows) to the constructor. The lcd.begin(16, 2) statement initializes the LCD. Finally, we use the lcd.print("Hello, World!") statement to display the text "Hello, World!" on the LCD.

The loop() function is empty in this example because we don't need any continuous action in the loop.

You can modify the code to customize the displayed text and experiment with other LCD functions provided by the LiquidCrystal_I2C library.

Remember to follow safety precautions while working with electronic components and circuits.

Here is the link for simulating and testing the project

Comments

Popular Posts