Challenge

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

Overview of the Project:

In this project implementing the Code for “Interfacing a 16*2 LCD with two Arduino’s (one for Master and one for Slave) using Inter-Integrated Circuit (I2C) communication protocol” by sending the message to LCD using I2C communication protocol and displaying the message on the LCD screen.

Goals:

  • Communication between Arduino and 16*2 LCD using I2C protocol.
  • Displaying the message sent by Master and received by slave i.e. LCD.

Key Highlights of the Project:

  • Using the inter-integrated circuit communication protocol, transferring the data i.e. the message we want to display is sent to the LCD.
  • Two Arduino’s are connected to the LCD display and the communication is executed using the I2C protocol between Arduino and the LDC display.

Deliverables of this project:

  • Communication between the Arduino’s and LCD using I2C.
  • The message passed from master to slave and displayed on the 16*2 LCD.

Expected Outcomes:

  • Students will get the Knowledge of I2C communication Protocol and the Arduino.
  • The Hardware connection of all components used in this project.
  • Displaying the message sent by master (Arduino) and received by the slave (16*2 LCD display).

Component used:

Name

Quantity

Component

UMaster
USlave

2

Arduino Uno R3

U4
U2

2

LCD 16 x 2

Rpot2

1

250 kΩ Potentiometer

R4
R1

2

1 kΩ Resistor

Schematic View:

Block diagram:

Program:

//master

#include <Wire.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

void setup()

{

Wire.begin();

lcd.begin(16, 2);

Serial.begin(9600);

}

void loop()

{

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("MasterSendVal:"); //Prints SlaveVal: in LCD

lcd.print(MasterSend); //Prints MasterReceive in LCD received from Slave

delay(500);

lcd.clear();

}

//slave

#include <Wire.h>

#include <LiquidCrystal.h>

byte SlaveReceived=0;

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);

void setup()

{

Wire.begin(8);//Begins I2C communication with Slave Address as 8 at pin (A4,A5)

lcd.begin(16, 2); //Initilize LCD display

Serial.begin(9600);//Begins Serial Communication at 9600 baud rate

Wire.onReceive(receiveEvent);// function call slave receive 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 the Slave receives value from the master

{

SlaveReceived = Wire.read(); //Used to read value received from master and store in variable SlaveReceived

}

Output:

the potentiometer value is conceded to the master message. Master sent to the slave and then receive value to print in LCD

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.