Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Master:
#include<Wire.h> //Library for I2C Communication functions
#include<LiquidCrystal.h> //Library for LCD display function
void setup()
{
pinMode(A1, INPUT);//input to A1 pin
Serial.begin(9600);//Braud rate
Wire.begin();//beginning
}
void loop()//loop start
{
float value=analogRead(A1);//analoge in that is voltage to A1 pin
signed int voltage=(value*5)/1024;// voltage caliculation assighned to voltage
Wire.beginTransmission(1);
Wire.write(voltage);
Wire.endTransmission();
delay(50);
}
Slave:
#include<Wire.h> //Library for I2C Communication functions
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);//Define LCD Module Pins (RS,EN,D4,D5,D6,D7)
void setup()
{
Serial.begin(9600);//braud rate
Wire.begin(1);
Wire.onReceive(LCD);//function call LCD
lcd.begin(16,2);//intialization of display
}
void loop()
{
delay(50);//delay 50 mlsec
}
void LCD(int y)//LCD function data printing and assining
{
signed int voltage=Wire.read();
lcd.setCursor(0,0);//set cursor first line of display
lcd.print("voltage");//print first line of LCD
lcd.setCursor(0,1);//second line of LCD
lcd.print(voltage);//voltage print
delay(50);//delay 50 mlsec
}