Challenge

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

OFFLINE BATCH-2

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

Expected Outcomes:

  • Students will get the Knowledge of I2C communication Protocol and the Arduino.
  • The Hardware connection of all components used in this project.
  • Displaying the message sent by master (Arduino) and received by the slave (16*2 LCD display).

MASTER:

//Master
#include<LiquidCrystal.h> // library for LCD function
#include<Wire.h> // library for I2C function
LiquidCrystal lcd(12,11,5,4,3,2); //define LCD pins

void setup()
{
lcd.begin(16,2); // initialize LCD dispaly
Wire.begin(); // begin I2C communication
Serial.begin(9600); // serial communication

}

void loop()
{
int v = analogRead(A0); // read analog value
byte mastersend = map(v,0,1023,0,127); //
Wire.requestFrom(1,1); // request 1 byte from slave
byte masterReceive= Wire.read();// receive a byte from slave
Wire.beginTransmission(1);// start trnsmit to slave
Wire.write(mastersend); // send one byte to slave
Wire.endTransmission(); // stop transmitting


lcd.setCursor(0,0); // set cursor at line one of lcd
lcd.print(" < Master > ");
lcd.setCursor(0,1); // set cursor at line two of lcd
lcd.print("slave value :");
lcd.print(masterReceive); // print data receive from slave
Serial.println("master receive from slave");
Serial.println(masterReceive); // print in serial monitor
delay(500);


}

SLAVE:

//slave
#include<LiquidCrystal.h> // library for LCD function
#include<Wire.h> // library for I2C function
LiquidCrystal lcd(12,11,5,4,3,2); //define LCD pins
byte slavereceive=0;
void setup()
{
lcd.begin(16,2); // initialize LCD dispaly
Wire.begin(1); // begin I2C communication
Serial.begin(9600); // serial communication
Wire.onReceive(receiveEvent); // function call when slave receives
Wire.onRequest(requestEvent); // function call when master request

}

void loop()
{

lcd.setCursor(0,0); // set cursor at line ione
lcd.print("< Slave > ");
lcd.setCursor(0,1); //set cursor at line two
lcd.print("Master Value :");
lcd.print(slavereceive); // print value receive from master
Serial.println("slave receive from master");
Serial.println(slavereceive); // print in serial monitor
delay(1000);
}

void receiveEvent(int many) // function call when slave receive
{
slavereceive = Wire.read(); // read and store in slave

}

void requestEvent() // function call when master wants data
{
int potvalue = analogRead(A0); //read analog value
byte slavesend = map (potvalue,0,1023,0,127); // convert digital value

Wire.write(slavesend); //send byte converted pot value to master
}

BEFORE:

AFTER:

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.