Challenge

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

OFFLINE B1

#include // header file
void setup() 
{
Serial.begin(9600); // to enable serial monitor
Wire.begin(1); // to enable i2c communication
}

void loop()
{
Wire.requestFrom(8,1); //request input from slave1
int x = Wire.read(); // read input from slave1
Serial.print("the temperature at node 8");
Serial.println(x); // print temperature in one room
Wire.requestFrom(9,1); //request input from slave2
int y = Wire.read(); // read input from slave2
Serial.print("the temperature at node 9");
Serial.println(y);// print temperature in another room

delay(1000); // Wait for 1000 millisecond(s)

}

slave 1

#include// header file
void setup()
{
pinMode(A0,INPUT);// set input
Serial.begin(9600);
Wire.begin(8);
Wire.onRequest(room_1);
}

void loop()
{
delay(50); // Wait for 1000 millisecond(s)
}
void room_1()
{
int value = analogRead(A0);
float volt = (value*5)/1024;
int temp = ((volt - 0.5)*100);
//Serial.print(temp);
Wire.write(temp);
}

slave 2

#include
void setup()
{
pinMode(A0,INPUT);
Serial.begin(9600);
Wire.begin(9);
Wire.onRequest(room_2);
}

void loop()
{
delay(50); // Wait for 1000 millisecond(s)
}
void room_2()
{
int value = analogRead(A0);
float volt = (value*5)/1024;
int temp = ((volt - 0.5)*100);
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.