Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

LCD+I2C: Displaying Information on Arduino with I2C Communication

In this article, we will explore how to use an LCD display with I2C communication on Arduino. LCD displays are commonly used to provide visual feedback in Arduino projects, and using I2C communication allows us to reduce the number of pins required for connection. We will discuss the importance of this topic and how it aligns with the Arduino environment.

Project: We will create a simple project that displays a custom message on an LCD display using I2C communication. The objective of this project is to demonstrate how to connect and control an LCD display using I2C, and to provide a foundation for more complex projects involving LCD displays.

Components List:

  • Arduino board (1)
  • LCD display with I2C module (1)
  • Jumper wires (as required)

Examples:

  1. Connecting the LCD display with I2C module to Arduino:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

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

void setup() {
  // Initialize the LCD display
  lcd.begin(16, 2);
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("LCD+I2C Example");
}

void loop() {
  // No additional functionality in this example
}

Explanation:

  • We include the necessary libraries: Wire.h for I2C communication and LiquidCrystal_I2C.h for controlling the LCD display.
  • We create an instance of the LiquidCrystal_I2C class, specifying the I2C address of the LCD display (0x27) and the number of columns and rows.
  • In the setup() function, we initialize the LCD display, turn on the backlight, and print a message on the first line.
  • The loop() function is empty in this example.
  1. Displaying dynamic information on the LCD display:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.backlight();
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Temperature: ");
  lcd.print(getTemperature());
  lcd.print(" C");

  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(getHumidity());
  lcd.print(" %");

  delay(1000);
}

float getTemperature() {
  // Code to read temperature from a sensor
  return 25.5;
}

float getHumidity() {
  // Code to read humidity from a sensor
  return 50.0;
}

Explanation:

  • We use the same setup as in the previous example to initialize the LCD display.
  • In the loop() function, we continuously update the LCD display with dynamic information.
  • We define two functions, getTemperature() and getHumidity(), which simulate reading temperature and humidity values from sensors.
  • The temperature and humidity values are printed on the LCD display with appropriate labels.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.