Challenge

Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol

master 

#include
#include

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

void setup() {
// Initialize the I2C communication
Wire.begin();

// Initialize the LCD
lcd.init();
lcd.backlight();

// Send a message to the Slave Arduino to display on the LCD
Wire.beginTransmission(9);
Wire.write("Hello from the Master Arduino!");
Wire.endTransmission();
}

void loop() {
// Nothing to do in the loop
}

slave

#include
#include

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

void setup() {
// Initialize the I2C communication
Wire.begin(9);
Wire.onReceive(receiveEvent);

// Initialize the LCD
lcd.init();
lcd.backlight();
}

void loop() {
// Nothing to do in the loop
}

void receiveEvent(int length) {
// Read the message sent by the Master Arduino
char message[100];
int i = 0;
while(Wire.available()) {
message[i] = Wire.read();
i++;
}
message[i] = '\0';

// Display the message on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(message);
}

CD Pin LCD Function I2C Pin Arduino Pin
1 GND GND GND
2 VCC VCC 5V
3 V0    
4 RS SDA A4 (SDA)
5 RW GND GND
6 EN SCL A5 (SCL)
7 D0    
8 D1    
9 D2    
10 D3    
11 D4 SDA A4 (SDA)
12 D5 SDA A4 (SDA)
13 D6 SDA A4 (SDA)
14 D7 SDA A4 (SDA)
15 LED+ VCC 5V
16 LED- GND GND
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.