Challenge

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

// Master Node:

/* PROJECT NAME: Interfacing a 16*2 LCD with Arduino using I2C protocol
*
* Created on: 13-11-2022
* Author: NOORUL AMEEN SHAIK MOHAMED
*
*/

#include<Wire.h> // Preprocessor Declaration for I2C protocol
#include<LiquidCrystal.h> // Preprocessor Declaration for LCD

LiquidCrystal lcd (2,7,8,9,10,11); //Arduino PINs for LCD communication

void setup()
{
lcd.begin(16,2);
Serial.begin(9600);
Wire.begin();
}

void loop()
{

Wire.requestFrom(1,1); // Request to send 1 Byte of Data from Slave Address 1
byte MasterReceived = Wire.read(); // Reading of Data which sent by Slave 1


int SNR_Value = analogRead(A0); // Reading of analog data from POT for Sending to Slave 1
byte Master_Send = map(SNR_Value,0,1023,0,255); // Changing read value 0 - 1023 to 0 - 255

Wire.beginTransmission(1);
Wire.write(Master_Send);// Sending of processed Data
Wire.endTransmission();

lcd.setCursor(0,0);
lcd.print(" MASTER ");
lcd.setCursor(1,1);
lcd.print("SLAVE DATA :");
lcd.print(MasterReceived ); // Displaying Received Slave Data on LCD Display
Serial.println(MasterReceived); // Displaying Received Slave Data on Serial monitor Display
delay(2000);
lcd.clear();
}

//Slave Code:

/* PROJECT NAME: Interfacing a 16*2 LCD with Arduino using I2C protocol
*
* Created on: 13-11-2022
* Author: NOORUL AMEEN SHAIK MOHAMED
*
*/

#include<Wire.h> // Preprocessor for I2C protocol
#include<LiquidCrystal.h> // Preprocessor for LCD

byte SlaveReceived = 0;
LiquidCrystal lcd(2,7,8,9,10,11); //Arduino PINs for LCD communication

void setup()
{
Serial.begin(9600);
Wire.begin(1);
lcd.begin(16,2);
Wire.onRequest(requestEvent); // Function on Request to Send Data to Master
Wire.onReceive(receiveEvent); // Function on Receive Date from Master
}

void loop()
{
lcd.setCursor(0,0);
lcd.print(" SLAVE ");
lcd.setCursor(0,1);
lcd.print("MASTER DATA:");
lcd.print(SlaveReceived); // Display Received data from Master on LCD
delay(2000);
lcd.clear();


}

// Function on Request to Send Data to Master
void requestEvent()
{

int SNR_Value = analogRead(A0);
int Slave_send = map(SNR_Value,0,1023,0,255);
Wire.write(Slave_send);
Serial.println(Slave_send);
}

// Function on Receive Date from Master
void receiveEvent(int howMany)
{
SlaveReceived = Wire.read();
}

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.