Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Aim
To implement 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 to LCD using I2C communication protocol and display the message on LCD screen.
Components Required
- Arduino Uno R3 (2)
- LCD 16 x 2 (2)
- 220 Ω Resistor(2)
Circuit Diagram

Using the Tinkercad and Arduino UNO to Interfacing two arduino uno using I2C protocol with Lcd display
Code
- Master(Sender)
#include
#include
const int SLAVE_ADDRESS=1;
LiquidCrystal lcd(12,11,5,4,3,2); //initialize lcd display
String myString="Hello Master!!"; //define string variable
void setup()
{
Serial.begin(9600); //start seial communication for debugging
lcd.begin(16,2); //initialize lcd display
Wire.begin(); //start I2C communication as the master
lcd.setCursor(0,0); //set cursor to 1st line
lcd.print("Mesage sent:"); //display "message sent" on lcd
lcd.setCursor(0,1); //set cursor to 2nd line
lcd.print(myString); //display "Hello Master!!" on lcd
}
void loop()
{
Wire.beginTransmission(SLAVE_ADDRESS); //start trannsmission to slave
Wire.write(myString.c_str()); //convert string to a C-style string with c_str() and send it over I2C
Wire.endTransmission(); //end transmission
delay(50); //small delay between transmission
}
- Slave(Receiver)
#include
#include
LiquidCrystal lcd(12,11,5,4,3,2); //initialize lcd display
const int SLAVE_ADDRESS=1;
void setup()
{
Serial.begin(9600); //start serial communication
Wire.begin(1); //start I2C communication with slave address 1
Wire.onReceive(ruso); //register the recieve event
lcd.begin(16,2); //initialize lcd display
}
void loop()
{
delay(50); //small delay to avoid busy-waiting
}
void ruso(int byteCount)
{
lcd.setCursor(0,0); //set cursor to 1st line
lcd.print("From Master"); //diplay "From Master" on lcd
lcd.setCursor(0,1); //set cursor to 2nd line
while(Wire.available())
{
char receivedChar=Wire.read(); //read the recieved data from sender
lcd.print(receivedChar); //display recieved data on lcd
Serial.print(receivedChar); //print recieved data to seial monitor
}
}
Execution
The communication between two Arduino boards using the I2C protocol and displays a message sent by the master Arduino on an LCD connected to the slave Arduino.
- Master Arduino
- The master Arduino initializes the LCD display using the LiquidCrystal library and defines a string variable myString with the value "Hello Master!!".
- In the setup() function, it starts the serial communication for debugging, initializes the LCD display, and begins the I2C communication as the master.
- The LCD display is used to show the message "message sent:" on the first line and the value of myString on the second line.
- In the loop() function, the master Arduino starts a transmission to the slave Arduino with the specified address (SLAVE_ADDRESS).
- It writes the content of myString to the I2C bus after converting it to a C-style string using the c_str() function.
- The transmission is ended, and a small delay is added between transmissions.
- Slave Arduino
- The slave Arduino initializes the LCD display using the LiquidCrystal library.
- In the setup() function, it starts the serial communication for debugging, initializes the LCD display, begins the I2C communication as a slave with address 1, and registers the ruso function to handle the receive event.
- In the loop() function, a small delay is added to avoid busy-waiting.
- The ruso function is called when the slave Arduino receives data from the master Arduino.
- Inside the ruso function, the LCD display is updated to show "From Master" on the first line.
- The received data is read from the I2C bus using the Wire.read() function and displayed on the LCD display.
- The received data is also printed to the serial monitor for debugging purposes.
Overall, the master Arduino sends the string variable myString to the slave Arduino using I2C communication. The slave Arduino receives the string and displays it on the LCD display, along with the message "From Master".
Output

I2C Protocol
The I2C (Inter-Integrated Circuit) protocol is a communication protocol that enables multiple devices to communicate with each other using a two-wire interface. It uses a master-slave architecture, where a master device initiates and controls the communication, and one or more slave devices respond to the master's requests. Communication occurs over two lines: SDA (Serial Data Line) for data transfer and SCL (Serial Clock Line) for synchronization.
Each slave device has a unique address, allowing the master to communicate with specific devices. Data is transferred in packets of 8 bits, and clock synchronization ensures reliable transmission. The protocol supports multi-master communication, enabling multiple master devices to share the same bus. Overall, the I2C protocol provides a simple and efficient means of interconnecting devices in embedded systems.
Key features of I2C protocol includes:
- Master-Slave Architecture: The communication in I2C is based on a master-slave relationship. The master device initiates and controls the communication, while one or more slave devices respond to the master's requests.
- Two-Wire Interface: I2C uses two lines for communication: SDA (Serial Data Line) and SCL (Serial Clock Line). SDA is bidirectional and carries data, while SCL is used to synchronize the data transfer.
- Addressing: Each slave device on the I2C bus has a unique address, allowing the master to communicate with specific slave devices. This enables the connection of multiple devices to the same bus.
- Data Transfer: Data is transferred in packets of 8 bits (bytes) between the master and the slave devices. Each byte is acknowledged by the receiver, ensuring reliable data transmission.
- Start and Stop Conditions: Communication in I2C starts with a start condition (SDA transitioning from high to low while SCL is high) and ends with a stop condition (SDA transitioning from low to high while SCL is high).