Sending Data Between Two Arduinos Using I²C Protocol
I²C (Inter-Integrated Circuit) is a two-wire serial communication protocol that allows multiple Arduino boards to communicate using a Master–Slave architecture.
1. Components Required
- 2 × Arduino Uno
- Jumper wires
- Breadboard (optional)
- LED or Serial Monitor for displaying received data
2. I²C Connections
| Arduino Master | Arduino Slave |
|---|---|
| A4 (SDA) | A4 (SDA) |
| A5 (SCL) | A5 (SCL) |
| GND | GND |
3. Master Arduino Program
The Master sends a message to the Slave every second.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <Wire.h> void setup() { Wire.begin(); // Join I2C bus as Master Serial.begin(9600); } void loop() { Wire.beginTransmission(8); // Slave address = 8 Wire.write(“Hello Slave”); Wire.endTransmission(); Serial.println(“Data sent: Hello Slave”); delay(1000); } |
4. Slave Arduino Program
The Slave receives the data and displays it on the Serial Monitor.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <Wire.h> void setup() { Wire.begin(8); // Join I2C bus with address 8 Wire.onReceive(receiveData); Serial.begin(9600); } void loop() { delay(100); } void receiveData(int bytes) { while (Wire.available()) { char c = Wire.read(); Serial.print(c); } Serial.println(); } |
5. Expected Output
Master Serial Monitor:
| Data sent: Hello Slave Data sent: Hello Slave Data sent: Hello Slave |
Slave Serial Monitor:
| Hello Slave Hello Slave Hello Slave |