Challenge

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

Answer

Objective: To send a meaasge from slave to master using Inter-Integrated Circuit (I2C) communication protocol in arduino and display the message on 16*2 LCD screen

The analog pins A4 and A5 in arduino are used for used for I2C communication. The digital pin 2 is connected to RS of LCD. Digital pin 3 connected to E of LCD. The Digital pins 4, 5, 6, 7 are connected to DB1, DB2, DB3, DB4 of LCD. Input supply 5v and Gnd are connected to the LCD from arduino. The potentiometer is used to turn ON and OFF the LCD.

CODE=

#include

#include

LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
byte SlaveReceived = 0; // Global variable (byte data type)

void setup()
{
lcd_1.begin(16, 2);
lcd_1.setCursor(0, 0);
lcd_1.print("Project on I2C communications");
for (int i = 0; i < 14; i++)
{
lcd_1.scrollDisplayLeft();
delay(150);
}

delay(2000);
lcd_1.clear();
Serial.begin(9600);
Wire.begin(1); // Wire communication start with address as 1
Wire.onReceive(receiveEvent); // caling function
Wire.onRequest(requestEvent); // caling function
pinMode(A0, INPUT);
}

void loop(void)
{
lcd_1.setCursor(0, 0); // Set cursor
lcd_1.print(" >> Slave LCD << "); // animation
lcd_1.setCursor(0, 1);
lcd_1.print(SlaveReceived); // Printing data coming from master arduion
lcd_1.print(" Master val");

}
void receiveEvent (int howMany) // This function is hepling in read data
{
SlaveReceived = Wire.read(); // store data in 'SlaveReceived'
}
void requestEvent()
{
float volt = analogRead(A0); // Reading analog value
volt = volt * 4.99; // conversion
float temperature = volt / 10;
byte SlaveSend = (temperature); // converted value
Wire.write(SlaveSend); // Sending converted valve
Serial.println(" Slave sending data to Master:"); // Printed on Serial Moniter
Serial.println(SlaveSend); // Slave valve is printing on Serial Moniter
}

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.