Challenge

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

/*Author : Kishore N

Date: 04-04-2025

*/

Answer

Component need:

  • 2 Arduino Uno

  • 16*2 I2C LCD Display

  • Breadboard

  • Jumper Wires

code:

#include <Wire.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD display

const int SLAVE_ADDRESS = 1;

void setup()

{

Serial.begin(9600); // Start the serial communication for debugging

Wire.begin(1); // Start the I2C communication as a slave with address 1

Wire.onReceive(ruso); // Register the receive event

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

}

void loop()

{

delay(50); // Small delay to avoid busy-waiting

}

void ruso(int byteCount)

{

lcd.setCursor(0, 0); // Set the cursor to the first line

lcd.print("from master:"); // Display "from master" on the LCD

lcd.setCursor(0, 1); // Set the cursor to the second line

while (Wire.available())

{

char receivedChar = Wire.read(); // Read the received data from the sender Arduino

lcd.print(receivedChar); // Display the received data on the LCD display

Serial.print(receivedChar); // Print the received data to serial for debugging

}

}

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.