Challenge

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

MASTER CODE

#include <Wire.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(">>TEMPERATURE SENSOR<<");
for(int i=0; i<16; i++)
{
lcd.scrollDisplayLeft();
delay(500);
}
delay(5000);
lcd.clear();
Serial.begin(9600);
Wire.begin();
}

void loop()
{ //code for slave
Wire.requestFrom(8,1);
byte MasterReceive = Wire.read();
Wire.beginTransmission(8);
Wire.endTransmission(8);
lcd.setCursor(0,0);
lcd.print("TEMPERATURE RECEIVED BY SLAVE = ");
lcd.print(MasterReceive);
for(int i=0; i<16; i++)
{
lcd.scrollDisplayLeft();
delay(500);
}
delay(5000);

}

SLAVE CODE

#include <LiquidCrystal.h>
#include <Wire.h>
byte SlaveReceived = 0;
LiquidCrystal lcd(12,11,5,4,3,2);

void setup()
{
Serial.begin(9600);
Wire.begin(8);
Wire.onRequest(requestEvent);
pinMode(A0, INPUT);
}

void loop()
{
delay(1000); // Wait for 1000 millisecond(s)
}

void requestEvent()
{
float volt = analogRead(A0);
volt = volt * 4.99;
float temperature = volt/10;
byte SlaveSend = (temperature);
Wire.write(SlaveSend);
lcd.setCursor(0,0);
lcd.print("TEMPERATURE RECEIVED BY SLAVE = ");
lcd.print(SlaveSend);
for(int i=0; i<16; i++)
{
lcd.scrollDisplayLeft();
delay(500);
}
delay(5000);
Serial.println("TEMPERATURE RECEIVED BY SLAVE = ");
Serial.println(SlaveSend);

}

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.