Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
INTERFACING 16X2 LCD USING I2C COMMUNICATION
I2C COMMUNICATION:
I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into devices for serial communication.
It is also known as Two Wired Interface(TWI). I2C is a synchronous, multi-controller/multi-target (master/slave), packet switched, single-ended, serial communication bus
PROGRAM:
I2C MASTER CODE:
#include
#include
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
byte SlaveReceived = 0; // Global variable (byte data type)
void setup()
{
lcd_1.begin(16, 2);
lcd_1.setCursor(0, 0);
lcd_1.print("Project on I2C communications");
for (int i = 0; i < 14; i++)
{
lcd_1.scrollDisplayLeft();
delay(150);
}
delay(2000);
lcd_1.clear();
Serial.begin(9600);
Wire.begin(1); // Wire communication start with address as 1
Wire.onReceive(receiveEvent); // caling function
Wire.onRequest(requestEvent); // caling function
pinMode(A0, INPUT);
}
void loop(void)
{
lcd_1.setCursor(0, 0); // Set cursor
lcd_1.print(" >> Slave LCD << "); // animation
lcd_1.setCursor(0, 1);
lcd_1.print(SlaveReceived); // Printing data coming from master arduion
lcd_1.print(" Master val");
}
void receiveEvent (int howMany) // This function is hepling in read data
{
SlaveReceived = Wire.read(); // store data in 'SlaveReceived'
}
void requestEvent()
{
float volt = analogRead(A0); // Reading analog value
volt = volt * 4.99; // conversion
float temperature = volt / 10;
byte SlaveSend = (temperature); // converted value
Wire.write(SlaveSend); // Sending converted valve
Serial.println(" Slave sending data to Master:"); // Printed on Serial Moniter
Serial.println(SlaveSend); // Slave valve is printing on Serial Moniter
}
TINKERCAD SIMULATION OUTPUT:
COMPONENTS USED:
- ARDUINO UNO
- BREADBOARD
- POTENTIO METER
- LCD 16X2 LCD
CONNECTIONS:

OUTPUT FOR WELCOME IN THE DISPLAY (MASTER/SLAVE):

COMMUNICATE BETWEEN THE MASTER AND SLAVE DISPLAY THE VALUES(TRANSMISSION/RECEPTION):
MASTER CODE SERIAL MONITOR OUPUT:

SLAVE CODE SERIAL MONITOR OUTPUT:

MASTER CODE SERIAL MONITOR OUPUT:

ADJUST POTENTIOMETER FROM MASTER(SEND) SIDE THE CHANGING VALUES DISPLAYED IN SLAVE (RECEIVE)DISPLAY AND ADJUST POTENTIOMETER FROM SLAVE(SEND) SIDE THE CHANGING VALUES DISPLAYED IN MASTER(RECEIVE) DISPLAY:
