Challenge

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

To implement a project that interfaces a 16x2 LCD with two Arduino boards (one acting as a Master and the other as a Slave) using the I2C communication protocol to send and display messages on the LCD screen, you'll need the following components:

Hardware:

  1. 16x2 LCD display module with I2C backpack (e.g., PCF8574).
  2. Two Arduino boards (e.g., Arduino Uno or Arduino Nano).
  3. Jumper wires.
  4. Power source (USB cable or batteries).

Software:

  1. Arduino IDE installed on your computer.
  2. Step 1: Hardware Connection

    1. Connect the I2C-enabled LCD display module to the Slave Arduino as follows:

      • SDA (Serial Data) on the I2C backpack to A4 on the Arduino.
      • SCL (Serial Clock) on the I2C backpack to A5 on the Arduino.
      • Connect the VCC and GND pins of the I2C backpack to 5V and GND on the Arduino.
      • Step 2: Master Arduino Code

        Write code for the Master Arduino that sends messages to the Slave Arduino. Here's a simple example:

        arduino
    2. Connect the Master Arduino to the Slave Arduino using a common ground (GND) connection.

Here are the steps to complete this project:

#include

void setup() {
  Wire.begin(); // Initialize I2C communication
}

void loop() {
  // Send a message to the Slave Arduino
  Wire.beginTransmission(8); // 8 is the I2C address of the Slave Arduino
  Wire.write("Hello, Slave!"); // Message to send
  Wire.endTransmission();

  delay(2000); // Wait for 2 seconds before sending the next message
}

Step 3: Slave Arduino Code

Write code for the Slave Arduino that receives messages from the Master Arduino and displays them on the LCD screen. You'll need to install the "LiquidCrystal_I2C" library if you haven't already:

  1. Go to "Sketch" -> "Include Library" -> "Manage Libraries..."
  2. Search for "LiquidCrystal_I2C" and click "Install" if it's not already installed.
  3. #include
    #include

    LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address (0x27) and LCD size (16x2)

    void setup() {
      Wire.begin(8); // Set the I2C address to 8
      Wire.onReceive(receiveEvent); // Set up the I2C receive event
      lcd.init(); // Initialize the LCD
      lcd.backlight(); // Turn on the LCD backlight
      lcd.setCursor(0, 0); // Set the cursor to the top-left corner
    }

    void loop() {
      // The loop can be left empty since we're using the receiveEvent callback
    }

    void receiveEvent(int howMany) {
      while (Wire.available()) {
        char c = Wire.read(); // Read the received character
        lcd.print(c); // Print the character on the LCD
      }

    }
  4. Step 4: Upload Code and Test

    1. Upload the Master Arduino code to one Arduino board and the Slave Arduino code to the other.

    2. Open the Serial Monitor for the Master Arduino to see if it's sending messages successfully. 

      1. Observe the LCD connected to the Slave Arduino. It should display the messages received from the Master Arduino

Now, here's an example of the Slave Arduino code:

Step 5: Document and Expand

Document your project with schematics, explanations, and code comments. You can expand this project by adding features like button controls or more advanced message handling between the Master and Slave Arduinos.

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.