All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
//I2C MASTERCODE//I2C communication between two arduino#include<Wire.h> //Library for I2C Communication functions#include<LiquidCrystal.h> //Library for LCD display functionLiquidCrystal lcd(2, 7, 8, 9, 10, 11); //Define LCD Module Pins (RS,EN,D4,D5,D6,D7) void setup() {lcd.begin(16,2); //Initilize…
divakar patel
updated on 25 Aug 2022
//I2C MASTERCODE
//I2C communication between two arduino
#include<Wire.h> //Library for I2C Communication functions
#include<LiquidCrystal.h> //Library for LCD display function
LiquidCrystal lcd(2, 7, 8, 9, 10, 11); //Define LCD Module Pins (RS,EN,D4,D5,D6,D7)
void setup()
{
lcd.begin(16,2); //Initilize LCD display
lcd.setCursor(0,0); //Sets Cursor at first line of Display
lcd.print("CYIENT"); //Prints CIRCUIT DIGEST in LCD
lcd.setCursor(0,1); //Sets Cursor at second line of Display
lcd.print("I2C MASTER ARDUINO"); //Prints I2C ARDUINO in LCD
delay(5000); //Delay for 5 seconds
lcd.clear(); //Clears LCD display
Serial.begin(9600); //Begins Serial Communication at 9600 baud rate
Wire.begin(); //Begins I2C communication at pin (A4,A5)
}
void loop()
{
Wire.requestFrom(8,1); // request 1 byte from slave arduino (8)
byte MasterReceive = Wire.read(); // receive a byte from the slave arduino and store in MasterReceive
int potvalue = analogRead(A0); // Reads analog value from POT (0-5V)
byte MasterSend = map(potvalue,0,1023,0,127); //Convert digital value (0 to 1023) to (0 to 127)
Wire.beginTransmission(8); // start transmit to slave arduino (8)
Wire.write(MasterSend); // sends one byte converted POT value to slave
Wire.endTransmission(); // stop transmitting
lcd.setCursor(0,0); //Sets Currsor at line one of LCD
lcd.print(">> Master <<"); //Prints >> Master << at LCD
lcd.setCursor(0,1); //Sets Cursor at line two of LCD
lcd.print("SlaveVal:"); //Prints SlaveVal: in LCD
lcd.print(MasterReceive); //Prints MasterReceive in LCD received from Slave
Serial.println("Master Received From Slave"); //Prints in Serial Monitor
Serial.println(MasterReceive);
delay(500);
lcd.clear();
}
//I2C SLAVE CODE
//I2C Communication between Two Arduino
#include<Wire.h> //Library for I2C Communication functions
#include<LiquidCrystal.h> //Library for LCD display function
LiquidCrystal lcd(2, 7, 8, 9, 10, 11); //Define LCD Module Pins (RS,EN,D4,D5,D6,D7)
byte SlaveReceived = 0;
void setup()
{
lcd.begin(16,2); //Initilize LCD display
lcd.setCursor(0,0); //Sets Cursor at first line of Display
lcd.print("CYIENT"); //Prints CIRCUIT DIGEST in LCD
lcd.setCursor(0,1); //Sets Cursor at second line of Display
lcd.print("I2C SLAVE ARDUINO"); //Prints I2C ARDUINO in LCD
delay(5000); //Delay for 5 seconds
lcd.clear(); //Clears LCD display
Serial.begin(9600); //Begins Serial Communication at 9600 baud rate
Wire.begin(8); //Begins I2C communication with Slave Address as 8 at pin (A4,A5)
Wire.onReceive(receiveEvent); //Function call when Slave receives value from master
}
void loop(void)
{
lcd.setCursor(0,0); //Sets Currsor at line one of LCD
lcd.print(">> Slave <<"); //Prints >> Slave << at LCD
lcd.setCursor(0,1); //Sets Cursor at line two of LCD
lcd.print("MasterVal:"); //Prints MasterVal: in LCD
lcd.print(SlaveReceived); //Prints SlaveReceived value in LCD received from Master
Serial.println("Slave Received From Master:"); //Prints in Serial Monitor
Serial.println(SlaveReceived);
delay(500);
lcd.clear();
}
void receiveEvent (int howMany) //This Function is called when Slave receives value from master
{
SlaveReceived = Wire.read(); //Used to read value received from master and store in variable SlaveReceived
}
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week-3 Challenge: ADVISOR Tool
1.For EV_defaults_in file, if cargo mass is 500 kg with all other default conditions, can the vehicle travel for 45 km with FTP drive cycle? Conclude your observations. Select the EV_defaults_in from the drop down menu in the load file section Change the cargo mass to 500kg Now click on the continue button a new window…
16 Feb 2024 03:57 AM IST
Project 2 - Measuring distance of an object using ultrasonic sensor (HC-SR04)
20 Jan 2023 04:16 PM IST
Project 1 - Controlling a DC motor using PWM and monitoring its Running status
20 Jan 2023 04:10 PM IST
Project 2 - V&V SW Analysis II
#ifndef FILE#include#endif #ifndef FALSE#define FALSE 0#define TRUE 1#endif /** this define determines if we are using stubs -* set to 0 for stubs or 1 for no stubs*/#define no_stubs 1 /** this define determines the interface to use* set to 1 for original interface or 0 for changed interface*/#define original_interface…
02 Jan 2023 04:09 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.