Arduino I2C Communication Tutorial: Master-Slave with Proteus

Arduino I2C Communication Tutorial: Master-Slave with Proteus

Published on January 1, 2025 | By ArduinoUnoProjex

Unlock the power of Arduino I2C communication with this beginner-friendly tutorial! Learn to connect two Arduino Uno boards using the I2C protocol in Proteus, with one as the Master and the other as the Slave. This guide covers wiring, code, and simulation to send data and control an LED, perfect for mastering Arduino I2C Master-Slave projects. Start with our recommended products and build your skills today!

Note: Amazon product links are included for convenience (not ours, just recommendations). ELEGOO boards are not Arduino but are compatible with Arduino IDE and much more affordable.

Recommended
Why Buy?
The ultimate Raspberry Pi 5 starter kit—perfect for advanced DIY projects, programming, and STEM education. Includes 8GB RAM, 128GB storage, and quality components. Ideal for makers, students, and educators!
Mega Power
Why Buy?
Best value Arduino Mega compatible board for complex robotics, 3D printing, and automation projects. Massive I/O, robust ATmega2560 microcontroller, and seamless compatibility with Arduino IDE.
Sensor Kit
Why Buy?
Explore 37 different sensors and modules—ideal for learning coding, IoT, robotics, and all levels of Arduino experimentation. Includes tutorials and code samples.
Must-Have
Why Buy?
Quality jumper wires for all breadboard and prototyping needs. Durable, flexible, and color-coded—essential for every electronics toolkit.
USB to Serial
Why Buy?
Connect your microcontrollers to your computer fast! CH340 USB to Serial modules are ideal for flashing, debugging, and uploading code to Arduino, ESP32, and more.

What is I2C Communication?

What is I2C and how does it work with Arduino? The Inter-Integrated Circuit (I2C) protocol enables efficient communication between microcontrollers and peripherals using two wires: SDA (Serial Data) and SCL (Serial Clock). Each device has a unique address, making I2C ideal for Arduino I2C projects like sensor networks or multi-device systems.

Benefits: Simple wiring, supports multiple devices, and reliable for short-distance communication.

Components Needed

To build this Arduino I2C Master-Slave system in Proteus, gather these components:

  • Arduino Uno or ELEGOO Uno R3 (x2, Arduino IDE-compatible)
  • LED (with 220Ω resistor)
  • Breadboard & Jumper Wires
  • Proteus Software (for simulation)
  • USB Cable for Arduino

Optional: USB-to-Serial module (e.g., CH340) for debugging.

Setting Up I2C Communication in Proteus

How do I implement I2C communication between two Arduinos in Proteus? Follow these steps to configure the Master and Slave Arduinos.

Wiring Instructions

Arduino I2C wiring schematic
Figure 1: I2C wiring schematic for two Arduino Uno boards
1

Connect SDA and SCL: Link the SDA (A4) and SCL (A5) pins of both Arduinos in Proteus.

2

Add LED: Connect an LED to pin 13 of the Slave Arduino via a 220Ω resistor, with the cathode to GND.

3

Add Virtual Terminal: In Proteus, place a Virtual Terminal (Place > Virtual Instrument > Virtual Terminal) to display the Slave’s Serial Monitor output.

Proteus virtual terminal placement
Figure 2: Placing a Virtual Terminal in Proteus
Proteus virtual terminal selection
Figure 3: Selecting the Virtual Terminal in Proteus

💡Tip: Ensure pull-up resistors (4.7kΩ) are added to SDA and SCL lines in physical setups to stabilize I2C communication.

Arduino I2C Master Code

What code runs the I2C Master Arduino? This code sends data to the Slave Arduino with address 6.


#include 

int LED = 13; // LED pin (optional for Master)

void setup() {
  Wire.begin(); // Join I2C bus as Master
}

byte x = 0;

void loop() {
  Wire.beginTransmission(6); // Transmit to Slave (address 6)
  Wire.write("x is ");       // Send message
  Wire.write(x);             // Send incrementing value
  Wire.endTransmission();    // Stop transmission
  x++;
  delay(500); // Wait 0.5 seconds
}
        

Code Breakdown

  • Library: Wire.h enables I2C communication.
  • Setup: Wire.begin() initializes the Master.
  • Loop: Sends “x is” and an incrementing x to the Slave every 0.5 seconds.

Keywords: Arduino I2C Master code, I2C communication Arduino, Proteus I2C simulation.

Arduino I2C Slave Code

What code runs the I2C Slave Arduino? This code receives data, displays it on the Serial Monitor, and blinks an LED.


#include 

int LED = 13;

void setup() {
  pinMode(LED, OUTPUT);         // Set LED pin as output
  Wire.begin(6);               // Join I2C bus with address 6
  Wire.onReceive(receiveEvent); // Register receive event
  Serial.begin(9600);          // Start Serial Monitor
}

void loop() {
  delay(100); // Wait for data
}

void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // Loop through all but last byte
    char c = Wire.read();       // Read byte as character
    Serial.print(c);            // Print to Serial Monitor
    digitalWrite(LED, HIGH);    // Turn LED on
    delay(1000);
    digitalWrite(LED, LOW);     // Turn LED off
    delay(500);
  }
  int x = Wire.read();          // Read last byte as integer
  Serial.println(x);            // Print integer
}
        

Code Breakdown

  • Setup: Sets LED pin, assigns address 6, and registers receiveEvent for incoming data.
  • receiveEvent: Reads characters, prints to Serial Monitor, blinks LED, and prints the final integer.
  • Loop: Waits for Master data with a 100ms delay.

Keywords: Arduino I2C Slave code, I2C Master-Slave Arduino, Arduino Proteus I2C tutorial.

Running the Proteus Simulation

How do I simulate I2C communication in Proteus? Follow these steps to test the setup.

1

Set Up Components: Place two Arduino Unos, connect SDA (A4) and SCL (A5), add an LED to Slave pin 13, and include a Virtual Terminal.

2

Load Codes: Upload the Master and Slave codes to their respective Arduinos in Proteus.

3

Run Simulation: Start the Proteus simulation and observe the Virtual Terminal output.

Arduino I2C Proteus simulation output
Figure 4: I2C data output in Proteus Virtual Terminal

Expected Result: The Virtual Terminal shows “x is” followed by incrementing numbers, and the LED on pin 13 blinks.

I2C vs. SPI: A Comparison

How does I2C compare to SPI for Arduino projects? Both are popular communication protocols, but they differ in key ways.

Feature I2C SPI
Wires 2 (SDA, SCL) 4 (MOSI, MISO, SCK, SS)
Speed Up to 400 kHz Up to 10 MHz
Devices Multiple (address-based) Multiple (chip select pins)
Complexity Simpler wiring More pins, faster

Recommendation: Use I2C for projects with multiple devices and simple wiring; choose SPI for high-speed applications.

Recommended Products

Start your Arduino I2C communication project with these high-quality components from Amazon (affiliate links). ELEGOO boards are Arduino IDE-compatible and budget-friendly.

Troubleshooting I2C Communication

  • ⚠️No Data on Virtual Terminal: Verify SDA/SCL connections and ensure the Slave address is 6.
  • ⚠️LED Not Blinking: Check pin 13 wiring and resistor on the Slave Arduino.
  • ⚠️Proteus Crash: Ensure correct Arduino models and simulation clock speed (e.g., 16 MHz).
  • ⚠️I2C Bus Errors: Add 4.7kΩ pull-up resistors to SDA/SCL in physical setups or Proteus.

Advanced I2C Project Ideas

  • 🚀Add an I2C LCD to display received data on the Slave.
  • 🚀Connect multiple Slaves (e.g., sensors) to the Master for a sensor network.
  • 🚀Integrate an ESP32 for Wi-Fi-enabled I2C data logging.
  • 🚀Use I2C to control a servo motor based on Master commands.

Frequently Asked Questions

How do I implement I2C communication between two Arduinos in Proteus?

Connect SDA (A4) and SCL (A5) pins of two Arduino Unos, assign the Slave address 6, load the Master and Slave codes, and run the Proteus simulation with a Virtual Terminal.

Why is my I2C Slave not receiving data in Proteus?

Check SDA/SCL connections, verify the Slave address (6), and ensure pull-up resistors are added to the I2C bus.

Can I use ELEGOO boards for I2C projects?

Yes, ELEGOO boards like Uno R3 or MEGA R3 are fully compatible with Arduino IDE and work perfectly for I2C communication.

Conclusion

This Arduino I2C communication tutorial equips you to build a Master-Slave system using two Arduino Unos in Proteus. You’ve learned to wire SDA/SCL, code Master and Slave Arduinos, and simulate data transfer with a blinking LED. Download the project files here, explore our recommended products, and check out our Arduino tutorials for more inspiration. Share your I2C creations in the comments and spark the maker community! 🔌

Post a Comment

0 Comments