Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Project: Interfacing a 16x2 LCD with Two Arduinos using I2C Protocol
Overview
In this project, we will establish communication between two Arduino boards—one acting as the Master and the other as the Slave—using the I2C communication protocol. The Slave will be connected to a 16x2 LCD, which will display messages sent from the Master.
Goals
- Establish I2C communication between Arduino and the 16x2 LCD.
- Successfully display messages sent from the Master Arduino on the LCD.
Key Highlights
- Utilizing the I2C protocol to transfer messages to the LCD.
- Connecting two Arduinos to control and display data on the LCD.
Deliverables
- Successful I2C communication setup.
- Message sent from the Master Arduino displayed on the 16x2 LCD.
Expected Outcomes
- Understanding of I2C communication protocol.
- Knowledge of hardware connections required for the project.
- Practical experience in sending and displaying messages using an LCD.
Components Required
- Two Arduino Boards (e.g., Arduino Uno)
- 16x2 LCD with I2C Module
- I2C LCD Library (e.g.,
LiquidCrystal_I2Cfor Arduino) - Jumper Wires
- Breadboard (optional)
Hardware Connections
LCD to Arduino Connections:
- VCC to 5V
- GND to GND
- SDA to A4 (on Uno)
- SCL to A5 (on Uno)
Master Arduino:
- Connect SDA and SCL pins to the corresponding pins on the Slave Arduino.
Software Setup
Libraries Required
Wire.hfor I2C communication.LiquidCrystal_I2C.hfor controlling the LCD.
Arduino Code
Master Arduino Code:-
#include <Wire.h>
#define SLAVE_ADDR 0x27 // Change this according to your LCD I2C address
void setup() {
Wire.begin(); // Join I2C bus as Master
Serial.begin(9600);
}
void loop() {
String message = "Hello, LCD!";
Wire.beginTransmission(SLAVE_ADDR); // Start communication with slave
Wire.write(message.c_str()); // Send the message
Wire.endTransmission(); // Stop communication
delay(2000); // Wait for 2 seconds before sending again
}
Slave Arduino Code:-
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SLAVE_ADDR 0x27 // Change this according to your LCD I2C address
LiquidCrystal_I2C lcd(SLAVE_ADDR, 16, 2); // Initialize LCD
void setup() {
Wire.begin(SLAVE_ADDR); // Join I2C bus as Slave
Wire.onReceive(receiveEvent); // Register receive event
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
}
void loop() {
// Do nothing here, waiting for messages
}
void receiveEvent(int numBytes) {
String message = "";
while (Wire.available()) {
char c = Wire.read(); // Read character
message += c; // Append character to message
}
lcd.clear(); // Clear LCD
lcd.print(message); // Display message
}
Testing the Project
- Upload the Master code to the first Arduino.
- Upload the Slave code to the second Arduino connected to the LCD.
- Ensure both Arduinos are powered and connected correctly.
- Observe the LCD display; it should show the message sent from the Master Arduino.