Challenge

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

                                                                                                Offline

#include//header file for i2c
void setup()
{
  Serial.begin(9600);//to view the serial monitor
  Wire.begin();//to enable i2c
 pinMode(A0,INPUT);//ouput for A0
 
 
}

void loop()
{
 
  float x=analogRead(A0);//to read analog input A0
  float value=((x*5)/1024);
 signed int temp=((value-0.5)*100);//value for temperature
  Wire.beginTransmission(8);//transmit for start
  Wire.write(temp);//write the temp value
  Wire.endTransmission();//transmit for end
 
  delay(1000);//delay for 1sec
}


#include//header file for i2c
#include//header file for lcd

void setup()
{
  LiquidCrystal lcd(12,11,5,4,3,2);//define lcd module pin RS,E,DB4,DB5,DB6,DB7
  lcd.begin(16,2);//initialize lcd display
 
 Serial.begin(9600);//to view serial monitor
  Wire.begin(8);//to enable the i2c
  Wire.onReceive(display);//function call when slave receive the signal
}

void loop()
{
 
  delay(30); // Wait for 1000 millisecond(s)
 
 
}
void display(int x)
{
  LiquidCrystal lcd(12,11,5,4,3,2);//define lcd module pin RS,E,DB4,DB5,DB6,DB7
  int y=Wire.read();//the value for temp
  Serial.println(y);//to view the serial monitor value of y
 lcd.setCursor(0,0);
  lcd.print("the volt is");//to dispaly the lcd
  lcd.print(y);//to display the value of y
  delay(1000);//delay for 1sec
}

 
 
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.