Challenge

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

OFF_LINE_BATCH;

// C++ code
//master


#include<Wire.h>

void setup()
{
Wire.begin();//library function
pinMode(A0,INPUT);//to set analog pin as input



}
void loop()
{

int x = analogRead(A0);
signed int v = ((x*5)/1024);
Wire.beginTransmission(8);
Wire.write(v);
Wire.endTransmission();
delay(1000);
}

// C++ code
//slave
#include<Wire.h>
#include<LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
Serial.begin(9600);//baud rate
Wire.begin(8);
Wire.onReceive(volt);//receive from master
lcd.begin(16,2);//lcd rows and colums

}
void loop()
{

delay(1000);


}
void volt(int y)//callling function
{
signed int v = Wire.read();
lcd.setCursor(0,0);

lcd.print("Voltage is");
lcd.print(v);
Serial.print("Voltage is");
Serial.println(v);
delay(1000);
}

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.