Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Aim : The project is to send a signal from master to slave using I2C as HIGH or LOW, so that based on input.
Circuit explaination:
Requirements:
2 Arduino UNO.
2 Rheostat.
2 LCD displays.
Resistors(required values)
Wires.
1 switch.
1 LED.
Software Used : Thinker CAD
For master :
Intigrated LCD display with arduino: 11,10,5,4,3,2 (RS, E, data pins).
Initiate as 7 as INPUT pin for switch to send high and low signal.
For slave :
Intigrated LCD display with arduino: 11,10,5,4,3,2 (RS, E, data pins).
Initiate as 12 pin as OUTPUT with a resistor.
In between : connected via A4,A5 pins from master to slave to communication.

Master Code :
#include
#include
LiquidCrystal lcd(11,10,5,4,3,2); // intitiated lcd, Enable switch, reset , data pins
int x; //inititated x as int in global
void setup()
{
lcd.begin(16,2); // intitiated as 16x2 as display
lcd.setCursor(0,0); // set cursor to print as master
lcd.print("This is master"); // printing as this si master to identify the value
Serial.begin(9600);
Wire.begin(); //initiated wire begin
pinMode(7,INPUT); //intitated pin 7 as input
}
void loop()
{
lcd.setCursor(0,1); // set cusror to display
if(digitalRead(7)==HIGH)
{
x=HIGH;
lcd.println("master sent:ON"); // desplaying as status
}
else{
x=LOW;
lcd.println("master sent:OFF"); //desplaying as status OFF
}
Wire.beginTransmission(9); // begin wire transmission as identity 9
Wire.write(x); // send signal to slave
Wire.endTransmission(); // ended transmission
}
Slave :
#include
#include
LiquidCrystal lcd(11,10,5,4,3,2);// intitiated lcd, Enable switch, reset , data pins
int x; //inititated x as int in global
void setup()
{
pinMode(13,OUTPUT); //declared as 13 pin output
Wire.begin(9); // begin 9 as a slave identity
Wire.onReceive(onrecieve); //if a signal recieved from any master intitate this
pinMode(13,OUTPUT); //declared 13 as output
lcd.begin(16,2); // intitiated as 16x2 as display
Serial.begin(9600); // intitated serial begin
lcd.setCursor(0,0); // seting cursor as 1st line
lcd.print("This is slave");// printed in display as slave
}
void onrecieve(int bytes)
{
x=Wire.read();
}
void loop()
{
if(x==HIGH) // if it is recieved HIGH do this function
{
lcd.setCursor(0,1); //set cursor to second line
lcd.println("recieved :ON"); //print the status
digitalWrite(13,HIGH); //change the pin to HIGH to see outpu changes.
}
else // else execute the below code.
{
lcd.setCursor(0,1);
lcd.println("recieved :OFF");
digitalWrite(13,LOW);
}
}