Challenge

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

//Slave
#include<Wire.h> //preprocessor directive for i2c
#include<LiquidCrystal.h> //preprocessor directive for lcd
LiquidCrystal lcd(12,11,5,4,3,2); //define lcd module pin(RS,EN,D4,D5,D6,D7)
void setup()
{
lcd.begin(16,2); //initialize lcd display
Wire.begin(1); //initialize i2c port and slave address set as 1
Wire.onReceive(display); //call function whenever new data is received over I2C
}
void loop()
{
delay(50); //delay
}

void display(int display) //display call function and take integer as an argument
{

int voltage=Wire.read(); //receive voltage from master arduino and display slave arduino
lcd.setCursor(0,0); //set cursor at 1st line
lcd.print("Voltage :"); //print function
lcd.print(voltage);
lcd.print("V");
delay(50); //delay

}

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.