Challenge

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

//Master
#include
#include
#define SLAVE_ADDR 16
Adafruit_LiquidCrystal lcd(32);

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

void loop()
{
Wire.beginTransmission(SLAVE_ADDR);
Wire.requestFrom(16,1);
temp=Wire.read();
Serial.println(temp);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temperature is ");
lcd.setCursor(0,1);
lcd.print(temp);
lcd.print(" deg C");
lcd.setBacklight(1);
delay(1000);
}

//slave
#include
#define SLAVE_ADDR 16
int sensorValue;
float v;
byte temp;

void setup()
{
Wire.begin(SLAVE_ADDR);
Wire.onRequest(requestEvent);

Serial.begin(9600);
}

void loop()
{
delay(1000);
}


void requestEvent()
{
sensorValue=analogRead(A1);
v=sensorValue*5.0/1023.0;
temp=100*v-50;
Wire.write(temp);

}

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.