Bird
0
0
Arduinoprogramming~30 mins

Connecting multiple I2C devices in Arduino - Mini Project: Build & Apply

Choose your learning style9 modes available
Connecting multiple I2C devices
📖 Scenario: You have two I2C sensors connected to your Arduino board. You want to read data from both sensors using their unique I2C addresses.
🎯 Goal: Write an Arduino program that initializes the I2C bus, communicates with two different I2C devices at addresses 0x3C and 0x68, and reads one byte of data from each device.
📋 What You'll Learn
Use the Wire library to communicate over I2C
Initialize the I2C bus in the setup() function
Read one byte from the device at address 0x3C
Read one byte from the device at address 0x68
Print the read bytes with labels to the Serial Monitor
💡 Why This Matters
🌍 Real World
Many electronics projects use multiple I2C sensors or modules connected to the same bus. Knowing how to communicate with each device by its address is essential.
💼 Career
Embedded systems engineers and IoT developers often work with multiple I2C devices to gather sensor data or control hardware. This skill is fundamental for hardware interfacing.
Progress0 / 4 steps
1
Setup I2C communication and Serial Monitor
Write void setup() function that starts the I2C bus with Wire.begin() and starts the Serial Monitor with Serial.begin(9600).
Arduino
Hint

Use Wire.begin() to start I2C and Serial.begin(9600) to start serial communication.

2
Create variables for I2C device addresses
Declare two const byte variables named device1Address and device2Address and set them to 0x3C and 0x68 respectively.
Arduino
Hint

Use const byte to define fixed I2C addresses.

3
Read one byte from each I2C device
In the loop() function, use Wire.beginTransmission() with device1Address, then Wire.requestFrom() to read one byte. Store it in byte data1. Repeat for device2Address storing in byte data2.
Arduino
Hint

Use Wire.beginTransmission(address) and Wire.requestFrom(address, 1) to read one byte from each device.

4
Print the read bytes to Serial Monitor
Add Serial.print() statements to print "Device 1 data: " followed by data1, and "Device 2 data: " followed by data2. Add Serial.println() to print each on a new line.
Arduino
Hint

Use Serial.print() and Serial.println() to show the data with labels.