Challenge

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

To communicate between two Arduino boards, one acting as a Master and the other as a Slave, using the I2C protocol in Tinkercad, follow these steps:

Step 1: Set up the Circuit

Open Tinkercad and create a new circuit.
Add two Arduino boards to the circuit canvas.
Connect the SDA pin of the Master Arduino to the SDA pin of the Slave Arduino.
Connect the SCL pin of the Master Arduino to the SCL pin of the Slave Arduino.
Connect the GND pins of both Arduinos together.
Step 2: Code the Slave Arduino

Select the Slave Arduino.
Select the LCD display & do the necessary connection.
Select the Slave Arduino and click on the "Code" button in the toolbar to open the code editor.

Slave Code

#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
char c;
void setup() {
Wire.begin(9); // Slave address is 8
Wire.onReceive(receiveEvent); // Register receiveEvent function
Serial.begin(9600); // Initialize Serial communication (optional)
lcd_1.begin(16, 2);
lcd_1.print("Receved Data");
}

void loop() {

// Additional code for the Slave Arduino to run, if needed
}

void receiveEvent(int howMany) {
while (Wire.available()) {
c = Wire.read(); // Read the incoming data character
Serial.print("Received data: ");
Serial.println(c); // Print received data to Serial Monitor (optional)
lcd_1.setCursor(0, 1);
// print the number of seconds since reset:
lcd_1.print(c);
}
}

Step 3: Code the Master Arduino

  • Select the Master Arduino.
  • Drag and drop the "Text" component from the Components panel onto the canvas.
  • Double-click the Text component and change its text to "Master".
  • Select the Master Arduino and click on the "Code" button in the toolbar to open the code editor.

#include <Wire.h>

#define SLAVE_ADDRESS 9

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

void loop() {
// Additional code for the Master Arduino to run, if needed

// Send data to the Slave Arduino
Wire.beginTransmission(SLAVE_ADDRESS); // Select Slave Arduino with address 9
Wire.write('S'); // Send data (can be a single character, integer, or array of bytes)
Wire.endTransmission();

delay(1000); // Delay between transmissions (optional)
}

Step 4: Test the Communication

  • Click on the "Start Simulation" button to start the simulation.
  • Open the Serial Monitor of the Master Arduino to view the communication between the two Arduinos.

Now, the Master Arduino will send data (character 'S') to the Slave Arduino using the I2C protocol, and the Slave Arduino will receive and print the data on the Serial Monitor (optional). The text components on the canvas will indicate the roles of the Arduinos (Master and Slave).

That's it! You have successfully set up communication between two Arduino boards acting as Master and Slave using the I2C protocol in Tinkercad.

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.