Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
MASTER CODE
#include//getting the wire I2C communication protocol
#include//getting the liquidcrystal library files
LiquidCrystal lcd(2,7,8,9,10,11);//(RS,EN,8,9,10,11)
int Mastersend=0;
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
Wire.begin();//begin communication for i2c in a4 and a5
}
void loop()
{
Wire.requestFrom(8,1);//getting the slave address
int tempvalue = analogRead(A0);//getting the analog value from tempearture sensor
Mastersend = map(tempvalue,0,1023,0,127);//converting to digial value
Wire.beginTransmission(8);
Wire.write(Mastersend);//sending the value to slave
Wire.endTransmission();
lcd.setCursor(0,0);
lcd.print("Master value");
lcd.setCursor(14,2);
lcd.print(Mastersend);//printing the value in LCD
Serial.println("Master value");
Serial.println(Mastersend);
}
SLAVE CODE
https://www.tinkercad.com/things/laDkZihSMqD-copy-of-i2c-engine/editel?sharecode=tat-Bvo2_DXThJ-8Uc0v2wKK7Wm1p_EgodnMREi3D4A