Challenge

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

In this project implementing the Code for “Interfacing a 16*2 LCD with two Arduino’s (one for Master and one for Slave) using Inter-Integrated Circuit (I2C) communication protocol” by sending the message to LCD using I2C communication protocol and display the message on LCD screen.

Code

Code

MASTER

#include
// Header to use I2C communication
#include
//pins connected to LCD
LiquidCrystal lcd(12,11,5,4,3,2);
byte X = 0;
byte Y = 0;
void setup()
{
//To begin I2C communication
Wire.begin();
}
void loop()
{
Wire.requestFrom(1,1);
byte X = Wire.read();
//To start the LCD display
lcd.begin(16,2);
//To move the cursor to the begining
lcd.setCursor(0,0);
//To display in LCD
lcd.print("Temp Room 1");
//To move the cursor to the next line
lcd.setCursor(0,1);
lcd.print(X);
//To display in LCD
lcd.print("Deg celcuis");
//delay 1sec
delay(1000);
lcd.clear();

Wire.requestFrom(2,1);
byte Y = Wire.read();
//To start the LCD display
lcd.begin(16,2);
//To move the cursor to the begining
lcd.setCursor(0,0);
//To display in LCD
lcd.print("Temp Room 2");
//To move the cursor to the next line
lcd.setCursor(0,1);
lcd.print(Y);
//To display in LCD
lcd.print("Deg celcuis");
//delay 1sec
delay(1000);
lcd.clear();
}

Slave 1 code

#include
void setup()
{
//To begin I2C communication
Wire.begin(1);
//function to send data
Wire.onRequest(requestEvent);
}
void loop(void)
{
}
void requestEvent()
{
//Reading analog data
float volt = analogRead(A0);
byte temp = map(volt,0,1023,0,127);
//writing converted data
Wire.write(temp);
}

Slave 2

 #include
void setup()
{
//To begin I2C communication
Wire.begin(2);
//function to send data
Wire.onRequest(requestEvent);
}
void loop(void)
{
}
void requestEvent()
{
//Reading analog data
float volt = analogRead(A0);
byte temp = map(volt,0,1023,0,127);
//writing converted data
Wire.write(temp);
}

Circuit diagram 

Output1

Output2 

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.