Challenge

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

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

CODE :

//MASTER ARDUINO
//I2C Communication between two arduino

//library for I2C communication function
#include <Wire.h>
//library for LCD display
#include <LiquidCrystal.h>
//Define LCD module pins
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
byte MasterSend ;

void setup()
{
//Begin I2C communication at A4,A5
Wire.begin();
//Begin Serial communication at 9600 band rate
Serial.begin(9600);
}

void loop()
{
//request 1 byte from slave arduino(2)
Wire.requestFrom(2,1);
//receive a byte from the slave arduino and store in masterReceived
byte MasterReceive = Wire.read();
//read analog value from value
float value = analogRead(A0);
//convert digital value (0 - 1023) to (0 - 127)
byte MasterSend = map (value,0,1023,0,127);
//start transmit to slave arduino
Wire.beginTransmission(2);
//send one byte converted value to slave
Wire.write(MasterSend);
//stop transmit
Wire.endTransmission();
//intialize LCD display
lcd_1.begin(16,2);
//set cursor at line one in LCD
lcd_1.setCursor(0, 0);
//print master ate LCD
lcd_1.print("MASTER ARDUINO");
//set cursor at line two in LCD
lcd_1.setCursor(0,1);
//print slave temperature ate LCD
lcd_1.print("SLAVE TEMP :");
//print master received in LCD received from slave
lcd_1.print(MasterReceive);
//print in serial monitor
Serial.println("Master Receieved From Slave");
//print the changing vlaue of temperature sensor
Serial.println(MasterReceive);
// Wait for 1000 millisecond(s)
delay(1000);
}

//SLAVE ARDUINO
//I2C Communication between two arduino


//library for I2C communication function
#include<Wire.h>
//library for LCD display
#include<LiquidCrystal.h>
//Define LCD module pins
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
byte SlaveReceived ;

void setup()
{
//intialize LCD display
lcd_1.begin(16,2);
//Begin Serial communication at 9600 band rate
Serial.begin(9600);
//Begin I2C communication at A4,A5
Wire.begin(2);
//Function call when slave receives value from master
Wire.onReceive(receiveEvent);
//Function call when master request value from slave
Wire.onRequest(requestEvent);
}

void loop()
{
//intialize LCD display
lcd_1.begin(16,2);
//set cursor at line one in LCD
lcd_1.setCursor(0,0);
//print slave arduino ate LCD
lcd_1.print("SLVAE ARDUINO");
//set cursor at line two in LCD
lcd_1.setCursor(0,1);
//print slave temperature ate LCD
lcd_1.print("SLAVE TEMP :");
//print slave received in LCD received from master
lcd_1.print(SlaveReceived);
//print in serial monitor
Serial.println("Slave Received From Master");
//print the changing vlaue of temperature sensor
Serial.println(SlaveReceived);
// Wait for 1000 millisecond(s)
delay(1000);
lcd_1.clear();
}
//This Function is called when slave receives value from master
void receiveEvent(int howmany)
{
//Used to read value received from master and store in variable slave received
SlaveReceived = Wire.read();
}
//This function is called when master wants value from slave
void requestEvent ()
{
//read analog value from value
float value = analogRead(A0);
//convert digital value (0 - 1023) to (0 - 127)
byte SlaveSend = map(value,0,1023,0,127);
//send one byte converted value to master
Wire.write(SlaveSend);
}

OUTPUT :

Master Receieved From Slave : 19 //Temperatue Changes when we adjust the temperature sensor

Slave Received From Master : 4 //Temperatue Changes when we adjust the temperature sensor

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.