Challenge

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

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

Code:

//Master Code

#include <Wire.h>. //for I2C communication

void setup()

{

Wire.begin(); // Initialize I2C communication

}

void loop()

{

//lcd.print("Hello");

Wire.beginTransmission(9); //initiates communication with the slave Arduino at address 9.

Wire.write("\nSkill-Lync"); //sends the message "Skill-Lync" to the slave Arduino

Wire.endTransmission(); //ends the transmission

delay(1000); //is used to introduce a 1-second delay before the loop repeats

}

//Slave Code

#include <LiquidCrystal.h>. //for interfacing with an LCD display

#include<Wire.h>

//Initialize an object of the LiquidCrystal library. This object is named lcd_1. Parameters represent the Arduino pins to which the LCD module is connected.

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

void setup()

{

Wire.begin(9);

Wire.onReceive(receiveData); //sets up the receiveData function to be called whenever data is received from the master Arduino

lcd_1.begin(16, 2); //initializes the LCD object with 16 columns and 2 rows

}

void loop()

{

}

//called whenever data is received from the master Arduino. The function receives the number of available bytes (howMany) and enters a loop while there are still bytes available.

voidreceiveData(inthowMany)

{

while(Wire.available() > 0)

{

char data = Wire.read(); // it reads each byte using Wire.read() and stores it in the data variable.

lcd_1.print(data); //The received character is then printed to the LCD

}

}

Overview of the Project:

1. Purpose: The project aims to establish communication between a master Arduino and a slave Arduino using the I2C protocol and display a message on an LCD.

2. Master Arduino:
- It uses the Wire.h library for I2C communication.
- The setup() function initializes I2C communication using `Wire.begin()`.
- In the loop() function:
- A message ("Hello Sadhana") is sent to the slave Arduino using `Wire.beginTransmission()` and `Wire.write()`.
- The transmission is ended with `Wire.endTransmission()`.
- A 1-second delay is added using `delay(1000)`.

3. Slave Arduino:
- It uses the Wire.h and LiquidCrystal.h libraries.
- The setup() function:
- Initializes I2C communication using `Wire.begin()` with the slave address (9).
- Sets up the `receiveData` function to handle received data using `Wire.onReceive()`.
- Initializes the LCD object (`lcd_1`) with the appropriate pin connections and size using `lcd_1.begin()`.
- The loop() function is empty and doesn't perform any actions.
- The `receiveData` function is called when data is received:
- It reads the received byte(s) using `Wire.read()`.
- The received character(s) are printed to the LCD using `lcd_1.print()`.

4. LCD Connections:
- The LCD module is connected to the Arduino as follows:
- RS pin: Arduino pin 12
- Enable (EN) pin: Arduino pin 11
- D4 pin: Arduino pin 5
- D5 pin: Arduino pin 4
- D6 pin: Arduino pin 3
- D7 pin: Arduino pin 2

Goals:

1. Establish Communication: The project aims to establish communication between a master Arduino and a slave Arduino using the I2C protocol. The master Arduino sends a message, and the slave Arduino receives and displays the message on an LCD.

2. Learn I2C Protocol: By implementing I2C communication between the master and slave Arduino, the project provides an opportunity to understand and work with the I2C protocol. This includes initializing the I2C communication, sending data from the master Arduino, and receiving data on the slave Arduino.

3. Interfacing with LCD: The project involves connecting and interfacing with an LCD module. The LCD module is connected to the slave Arduino, and the received message is displayed on the LCD screen. This allows for understanding how to control and display information on an LCD using Arduino.

4. Demonstrating Master-Slave Architecture: The project showcases a common architecture in communication systems, where a master device (master Arduino) initiates communication and controls the slave device (slave Arduino). Understanding this architecture is essential when working with systems involving multiple devices.

5. Hands-on Arduino Programming: The project provides a practical application for Arduino programming. By writing code to send and receive data, control the LCD module, and handle events, in programming Arduino boards.

6. Learning Electronics and Wiring: The project involves connecting and wiring the Arduino boards, LCD module, and other components.

Key Highlights of the Project:

1. I2C Communication: The code demonstrates the use of the I2C protocol for communication between a master Arduino and a slave Arduino. The master Arduino sends a message to the slave Arduino using the Wire library's `Wire.write()` function, and the slave Arduino receives the message using the `Wire.onReceive()` function.

2. Master-Slave Architecture: The code showcases a typical master-slave architecture where the master Arduino initiates communication and controls the slave Arduino. The master Arduino sends data, and the slave Arduino receives and processes the data.

3. LCD Interfacing: Although the LCD functionality is commented out in the code, it highlights the potential to interface with an LCD module using the LiquidCrystal library. The code initializes an LCD object (`lcd_1`) with specific pin connections and demonstrates how the received data can be printed on the LCD using the `lcd_1.print()` function.

4. Event-Driven Programming: The code utilizes the `Wire.onReceive()` function on the slave Arduino, which is an event-driven approach. Whenever data is received from the master Arduino, the `receiveData()` function is automatically called to handle the received data. This event-driven programming style allows for efficient and responsive handling of incoming data.

5. Delay Function: The `delay()` function is used in the master Arduino's `loop()` function to introduce a 1-second delay between consecutive message transmissions. This delay ensures that messages are not sent too rapidly, providing a pause between transmissions.

6. Libraries: The code includes the Wire library for I2C communication and the LiquidCrystal library for LCD interfacing. These libraries provide pre-defined functions and methods that simplify the implementation of the desired functionalities, such as initiating I2C communication, sending/receiving data, and controlling the LCD module.

Deliverables of this project:

1. Communication between Master and Slave: The code enables communication between a master Arduino and a slave Arduino using the I2C protocol. The master Arduino sends a message ("Skill-Lync"), and the slave Arduino receives and processes the message.

2. Display of Received Message: The slave Arduino is equipped with an LCD module connected to specific pins. The received message from the master Arduino is displayed on the LCD module. This allows for visual confirmation of successful communication and message reception.

3. Learning Resource: The code serves as a learning resource or example for understanding how to implement I2C communication and interface an LCD module with Arduino. It can be used as a reference to explore similar projects or gain a better understanding of I2C communication and LCD interfacing.

4. Hands-on Experience: By working with the code and implementing it on Arduino boards, we gain practical experience in coding, wiring, and testing Arduino projects. This hands-on experience helps to reinforce concepts related to I2C communication, LCD interfacing, and Arduino programming.

Expected Outcomes:

1. Successful Communication: The code aims to establish communication between the master and slave Arduino using the I2C protocol. The expected outcome is that the master Arduino successfully sends the message "Skill-Lync" to the slave Arduino.

2. Message Displayed on LCD: The slave Arduino is connected to an LCD module. The expected outcome is that the slave Arduino receives the message from the master Arduino and displays it on the LCD screen. The message "Skill-Lync" should be visible on the LCD.

3. Repeated Transmission: The code is designed to repeat the communication process in a loop. After a delay of 1 second using `delay(1000)`, the master Arduino should send the message again. The expected outcome is that the message transmission and LCD display occur repeatedly at 1-second intervals.

4. Learning Opportunity: Apart from the specific outcomes related to communication and display, the code provides a learning opportunity in Arduino programming, I2C communication, and interfacing with LCD modules. The expected outcome is to gain knowledge and hands-on experience in these areas, building their understanding of electronics and programming.

All the necessary screenshots are attached herewith

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.