Challenge

Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol

Aim:

“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.

Goals:

  • Communication between Arduino and 16*2 LCD using I2C protocol.
  • Displaying the message sent by Master and received by 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 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.

CODE:

MASTER CODE:

#include<LiquidCrystal.h> // Header to use LCD functions
#include<Wire.h> // Header to use I2C communication
LiquidCrystal lcd(2,3,4,5,6,7); //pins connected to LCD
void setup()
{
Serial.begin(9600);
Wire.begin(8); //To begin I2C communication
Wire.onRequest(send); //To call the send function
lcd.begin(16,2); //To start the LCD display
lcd.clear(); //To clear the display
}

void loop()
{
lcd.setCursor(0,0); //To move the cursor to the begining
lcd.print("MASTER"); //To display in LCD
lcd.setCursor(0,1); //To move the cursor to the next line
lcd.println("Mssage sent"); //To display in LCD
}
void send()
{
char ch[17]="SANJEEV"; //creating string
Wire.write(ch); //To send message to Master
}

SLAVE CODE:

//SLAVE CODE
#include<LiquidCrystal.h> // Header to use LCD functions
#include<Wire.h> // Header to use I2C communication

LiquidCrystal lcd(2,3,4,5,6,7); //pins connected to LCD
char slaveReceive[16]; //String to get the message

void setup()
{
Serial.begin(9600);
Wire.begin(); //To begin I2C communication
lcd.begin(16,2);
lcd.clear();
}

void loop()
{
Wire.requestFrom(8,16); //8 address 16 characters
lcd.setCursor(0,0); //To move the cursor to the begining
lcd.print("SLAVE"); //To print in display
lcd.setCursor(0,1); //To move the cursor to the next line
int i=0;
while(0<Wire.available()) //To check the number of bytes available
{
slaveReceive[i]=Wire.read(); //To print character by character
i++;
}
lcd.print(slaveReceive); //To print the received message
delay(1000); //Delay for 1 second
Wire.end(); //To end the I2C transmission
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.