In today’s world of interconnected devices, managing multiple microcontrollers efficiently can significantly enhance your project capabilities. One effective architecture is to use an Arduino as a master controller that orchestrates multiple slave microcontrollers for various tasks. This tutorial will guide you step-by-step on how to set this up, allowing your main Arduino board to communicate seamlessly with other microcontrollers.
Before we delve into the setup, let’s clarify some concepts:
To follow this tutorial, you will need:
Here’s how to connect the master Arduino to the slave microcontrollers using the I2C protocol:

In this setup, the Arduino Uno will act as the master. This means that the SDA (Serial Data Line) and SCL (Serial Clock Line) pins will be shared among all slave microcontrollers. Remember to connect the ground (GND) from all devices to avoid any communication glitches.
Now that we have our hardware all set up, let’s write the code for the master Arduino:
#include
#define SLAVE1_ADDRESS 8
#define SLAVE2_ADDRESS 9
void setup() {
Wire.begin(); // Initialize the I2C bus (Master)
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Requesting data from Slave 1
Wire.requestFrom(SLAVE1_ADDRESS, 1);
if (Wire.available()) {
int data = Wire.read(); // Read data from slave
Serial.print("Data from Slave 1: ");
Serial.println(data);
}
// Requesting data from Slave 2
Wire.requestFrom(SLAVE2_ADDRESS, 1);
if (Wire.available()) {
int data = Wire.read(); // Read data from slave
Serial.print("Data from Slave 2: ");
Serial.println(data);
}
delay(1000); // Delay for a second
}
For each of the slave microcontrollers, we will need to write a similar piece of code. Here’s an example for a slave device responding to requests:
#include
#define SLAVE_ADDRESS 8 // Change accordingly for each slave
int count = 0;
void setup() {
Wire.begin(SLAVE_ADDRESS); // Set the I2C address for the slave
Wire.onRequest(requestEvent); // Register event handler for request
}
void loop() {
delay(100); // Simulating some work
}
void requestEvent() {
Wire.write(count); // Send the counter value
count++; // Increment the counter
}
Once you upload the master and slave codes to their respective devices, open the Serial Monitor in the Arduino IDE. You should see output similar to:
Data from Slave 1: 0
Data from Slave 2: 0
Data from Slave 1: 1
Data from Slave 2: 1
…
This indicates that the master controller is successfully communicating with the slave devices, and they’re responding correctly.
Now that you have a basic setup working, there are many possibilities to expand its functionality:
Setting up an Arduino as a master controller to communicate with multiple slave devices can open up new avenues for your projects. By leveraging protocols like I2C, you can create a robust and scalable solution. This tutorial provided a foundational understanding, but remember, the potential is vast. Explore, experiment, and let your creativity lead the way!