Challenge

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

//code For Master Arduino-2

#include <Wire.h> // this lybrary use for I2C communicationwith master

// master and slave

// C++ code

void setup()

{

Wire.begin(); // this function describe in wire.h for begin Serial data

Serial.begin(9600); //intializing the serial monitor for showing the O/P

}

// this is our void loop function for infinity execution

void loop()

{

float val1=analogRead(A4); // analog voltage assign to variable

signed int voltage1=(val1*50)/1024;

Serial.println(voltage1);// showing data on serial monitor

Wire.beginTransmission(1);// I2C comm begining function

Wire.write(voltage1);

Wire.endTransmission();// I2C comm end by this function

delay(50);

}

//code For slave Arduino-1

#include <LiquidCrystal.h> // include LCD

#include <Wire.h>

// this lybrary use for I2C communication with master and slave

// C++ code

//initializing the variable lcd pin name

const int rs=12,en=11,d4=7,d5=6, d6=5, d7=4;

LiquidCrystal lcd(rs,en,d4,d5,d6,d7); // initialize the variable with the name lcd

void setup()

{

Serial.begin(9600);

Wire.begin(1);

Wire.onReceive(LCD); // this is use when any information received on wire call LCD function

lcd.begin(16,2);

}

void loop()

{

delay(50);

}

void LCD(int y)

{

signed int voltage1=Wire.read();

lcd.setCursor(0,0); // set cursor on dispaly 1st column and 1st row

lcd.print("the voltage is"); // print function on display

lcd.setCursor(1,1);// set cursor on dispaly 2nd column and 2nd row

lcd.print(voltage1);

Serial.print("voltage value in Volt on slave\n");

Serial.println(voltage1);

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.