Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Overview of the Project:
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 (value of potentiometer connected to Master) to LCD ( Connected to Slave) using I2C communication protocol and displaying the same message on the LCD screen.
Goals:
- Communication between Arduino and 16*2 LCD using I2C protocol.
- Displaying the message (value of potentiometer) sent by the Master and received by the slave i.e. LCD display.
Key Highlights of the Project:
- Using the inter-integrated circuit communication protocol, transferring the data i.e. the message we want to display is sent to the LCD.
- Two Arduino’s connected to the LCD display and the communication is executed using the I2C protocol between Arduino and the LDC display.
Deliverables of this project:
- Communication between the Arduino’s and LCD using I2C.
- The message passed from master to slave and displayed on the 16*2 LCD.
Circuit Diagram:

Master Coding
/* Master : Arduino with potentiometer having I2C communication
with 2 Arduino(Slave) */
#include<Wire.h> // Library for I2C Communication functions
# define Potentiometer A0
byte valb=0;
void setup()
{
Wire.begin();
Serial.begin(9600);
pinMode(A0, INPUT);
}
void loop()
{
int val;
val = analogRead(Potentiometer);
valb = map(val, 0,1023, 0, 127);
Serial.println(valb);
Wire.beginTransmission(1); // Start Transmisssion to slave arduino(1)
Wire.write(valb); // Sends 1 byte to slave 1
Wire.endTransmission(); // Stop Transmitting
delay(500);
}
Slave Coding
/*
Slave: Arduino with LCD and I2C Communication
with Master Arduino
*/
#include<Wire.h> // Library for I2C Communication functions
#include<LiquidCrystal.h> //Library for LCD display function
LiquidCrystal lcd(2,3,4,5,6,7); // Define LCD Module Pins (RS, EN, D4, D5, D6, D7)
byte global_variable;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin(1);// Begins I2C communication with slave address as 1 at pin (A4, A5)
lcd.begin(16,2); // Initilize LCD display.
lcd.setCursor(0,0); // Sets Cursor at first line of Display
lcd.print("---Value From---");
lcd.setCursor(0,1);
lcd.print("Master:");
Wire.onReceive(ReceiveFunction); // Function call when slave receives value from master
// I2C Interrupt handler.
}
void loop()
{
// put your main code here, to run repeatedly
lcd.setCursor(9,1);
lcd.print(global_variable);
Serial.println(global_variable);
delay(500);
}
void ReceiveFunction()
{
global_variable = Wire.read();
}