Challenge

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

#include // LCD Library
#include // Wire Library

LiquidCrystal lcd(2,3,4,5,6,7); // Initialisation of LCD
char msg[15];

void setup()
{
Serial.begin(9600); // For serial monitor
Wire.begin();
lcd.begin(16,2);
lcd.clear();
}

void loop()
{
Wire.requestFrom(2,4); // Requesting from arduino 2
lcd.setCursor(0,0); // LCD Cursor
lcd.print("MASTER");
lcd.setCursor(0,1);
int i=0;
while(0{
msg[i]= Wire.read();
i++;
}
lcd.print(msg); // Printing message
delay(1000);
Wire.end();
}

SLAVE CODE:

#include
#include

LiquidCrystal lcd(2,3,4,5,6,7);

void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
Wire.begin(2); // declaring Arduino as number 2
Wire.onRequest(message); // Sending message on request
}

void loop()
{
lcd.setCursor(0,0);
lcd.print("SLAVE"); // Printing message on LCD
lcd.setCursor(0,1);
lcd.print("message sent");
delay(50);
}

void message() // message function to send a message
{
char message[12] = "Hello World";
Wire.write(message);
}

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.