• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Control One Arduino From Another Arduino via I2C

By Abhishek Ghosh June 10, 2024 10:30 pm Updated on June 10, 2024

Control One Arduino From Another Arduino via I2C

Advertisement

Inter-Arduino communication opens up a world of possibilities for embedded systems and IoT projects. One powerful method for achieving this is using the I2C (Inter-Integrated Circuit) protocol. I2C enables seamless communication between microcontrollers, allowing for data exchange and control commands. In this article, we’ll delve into the process of controlling one Arduino board from another using I2C, exploring its principles, setup, and practical implementation.

Also Read: What is I²C Protocol? Relevance of I²C in Arduino

Here is Arduino’s official documentation:

Vim
1
https://docs.arduino.cc/learn/communication/wire/

 

Understanding I2C Communication

 

I2C is a synchronous serial communication protocol that facilitates communication between integrated circuits using only two wires: a data line (SDA) and a clock line (SCL). It operates in a master-slave architecture, where one device acts as the master and initiates communication, while the other devices act as slaves and respond to the master’s commands.

Advertisement

---

For example, the master device can generate clock pulses to synchronize data transmission and reception. Each slave device on the bus has a unique address, allowing the master to select the desired slave for communication. This address space enables multiple devices to coexist on the same bus.

 

Setting Up the Hardware

 

To control one Arduino from another via I2C, you’ll need two Arduino boards (one acting as the master and the other as the slave), along with some basic components:

  • Two Arduino boards (e.g., Arduino Uno, Nano, or Mega)
  • Connecting wires
  • Breadboard (optional, for prototyping)
  • One LED
  • One resistor – 220Ohm
  • One potentiometer
  • Power source (USB or external power supply)

Potentiometer works because of PWM. Read What is Pulse Width Modulation (PWM)?.

Connect the boards as follows:

Control One Arduino From Another Arduino via I2C

 

Implementing Master-Slave Communication

 

Now, let’s implement the master-slave communication between the two Arduinos:

Setting up the Slave Arduino (Arduino 2):

  1. Define a unique I2C address for the slave Arduino using the Wire.begin(address) function. It is Wire.begin(2) in our case.
  2. Implement callback functions to handle incoming data from the master.
  3. In the callback functions, process the received data and perform the desired actions.

In this case, we will read to the master Arduino and instruct the LED.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Wire.h>
 
const int ledPin = 10;  // Digital pin for LED
int brightness = 0;    // LED brightness
 
void setup() {
  Wire.begin(2);  // Initialize I2C communication with address 2
  Wire.onReceive(receiveEvent); // Set up function to receive I2C data
  pinMode(ledPin, OUTPUT); // Set LED pin as output
}
 
void loop() {
  // No need for additional code in the loop since we're using I2C interrupts
}
 
void receiveEvent(int byteCount) {
  if (byteCount == 1) {
    brightness = Wire.read(); // Read the value sent from Arduino 1
    analogWrite(ledPin, brightness); // Set LED brightness based on received value
  }
}

Setting up the Master Arduino (Arduino 1):

Basically it is easy to read from a potentiometer. The mapped value will be sent over I2C.

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <Wire.h>
 
const int potentiometerPin = A0;  // Analog pin for potentiometer
int potValue = 0;                 // Potentiometer value
 
void setup() {
  Wire.begin();  // Initialize I2C communication
}
 
void loop() {
  potValue = analogRead(potentiometerPin); // Read potentiometer value
  int mappedValue = map(potValue, 0, 1023, 0, 255); // Map to PWM range (0-255)
  
  // Send mapped value over I2C to Arduino 2
  Wire.beginTransmission(2); // Arduino 2's I2C address is 2
  Wire.write(mappedValue);
  Wire.endTransmission();
 
  delay(10); // Add a small delay to avoid excessive I2C communication
}

Here is the simulation:

 

Conclusion

 

Inter-Arduino communication via I2C provides a flexible and efficient way to control multiple Arduino boards in a networked environment. By understanding the principles of I2C communication and following the setup procedures, you can seamlessly integrate multiple Arduino devices into your projects, unlocking endless possibilities for automation, robotics, sensor networks, and more. Experiment with different scenarios and expand your knowledge of embedded systems and IoT applications with this powerful communication protocol.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Control One Arduino From Another Arduino via I2C

  • MySQL Configuration to Set Up Master-Slave Replication

    Master-Slave Replication For WordPress Makes it Fail Proof to WordPress Database Errors Making the Website Fully Unreadable.

  • What is I²C Protocol? Relevance of I²C in Arduino

    Previously, we discussed about UART. What is I²C Protocol? I squared C (also pronounced as I-two-C) or I²C is a bus serial communication protocol designed by Philips for home automation and home electronics applications. Since 2006, licensing fees not needed to implement the I²C protocol. Fees needed to obtain I²C slave addresses allocated by NXP. […]

  • ESP32 Arduino With LCD : Connection & Code (I2C, LCD 1602A)

    1602 LCD and I2C module are quite cheaper and easy to setup and code. Here are the Required Connection & Code to Use ESP32 With LCD.

  • Arduino LED Candle : Some Codes to Help You

    Thanks to China for making various designs of LED candles available all over the world. Indeed, most of these LED candles are not closest to the real candle, but they do give us the idea to think around playing around creating our microcontroller controlled LED candle. I was looking for a realistic feel and soon […]

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

vpsdime

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Cloud-Powered Play: How Streaming Tech is Reshaping Online GamesSeptember 3, 2025
  • How to Use Transcribed Texts for MarketingAugust 14, 2025
  • nRF7002 DK vs ESP32 – A Technical Comparison for Wireless IoT DesignJune 18, 2025
  • Principles of Non-Invasive Blood Glucose Measurement By Near Infrared (NIR)June 11, 2025
  • Continuous Non-Invasive Blood Glucose Measurements: Present Situation (May 2025)May 23, 2025
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2026 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy