Challenge

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

Program:

Master:

#include         

void setup()
{
 Serial.begin(9600);
 Wire.begin(1); 
 Wire.onRequest(requestEvent);
}

void loop()
{  
}

void requestEvent()
{
 float tempInCelsius = ((float(analogRead(A0))*5/1024)-0.5)/0.01;
 int tempInFahrenheit=(tempInCelsius*9.0/5.0)+32.0;
 Serial.print("Temperature reading: ");
 Serial.println(tempInFahrenheit);
 Wire.write(tempInFahrenheit);
}

Slave:

#include         
#include 

Adafruit_LiquidCrystal lcd(0);

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

void loop()
{
  Wire.requestFrom(1, 1);
  uint8_t dataReceived = Wire.read();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Room temperature: ");
  lcd.setCursor(0,1);
  lcd.print(dataReceived); 
  lcd.print(" \xB0""F");
  delay(1000);
}


Circuit:

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.