Challenge

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

Code-Master I2C:

#include<LiquidCrystal.h> //Library for LCD Functions operations//
#include<Wire.h> //Libraray for I2C Commnucation
int a=10;
void setup()
{
Serial.begin(9600); //Begin Serial communication
Wire.begin(); //Begin I2C Communication from master to slave
}

void loop()
{
Wire.beginTransmission(8); /Transmission started through slave address 8;
Wire.write(a); //Sending data to slave address 8
Serial.println(a); //Printing a value in master serial monitor
Wire.endTransmission();//Transmission ended
delay(500); //delay of 500 ms
}

Code-Slave I2C:

#include<LiquidCrystal.h>
#include<Wire.h>
LiquidCrystal lcd(12,11,5,4,3,2); //Initilaizing LCD Pins DS,E,DB4,DB5,DB6,DB7
int a;
void setup()
{
Wire.begin(8); //started communication through 8 slave address
Serial.begin(9600);
Wire.onReceive(receiveEvent);//receiving data from master through receiveEvent function call//
lcd.begin(16,2);//Initilizing LCD 16X2 (Rows and Colomuns)
}
void receiveEvent(int bytes)
{
a=Wire.read(); //received a value reading here
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);/Initial curse point 1 st row 1 st column//
lcd.print(a);//printing a value in LCD screen//
lcd.setCursor(1,2); 1st coumn and second row initilazation
lcd.print("Data Received!!"); //Printing Data received
Serial.println(a);
delay(50); //Delay of 50 ms
}

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.