Four sensors on one I²C bus
Found 0x3C, 0x40, 0x68, 0x76Tap a part to see what it does.
Tap the parts to see what each one does. A teaching simulation, not a circuit simulator.
Build it step by step
0 of 4 doneMake an I2C rail
Use one breadboard row for SDA and one for SCL so every module plugs into the same lines.
Add the modules one by one
Plug in one module, upload the scanner, check its address, then add the next.
Wire the INA219 load
Put the INA219 in series with a small LED load so it has some current to read.
Upload the dashboard
The OLED shows a new page every 2 seconds.
How do you build a four sensors on one I²C bus?
An ESP32 talks to a BME280, an INA219, an MPU6050 and an OLED on the same two wires, scans the bus at start-up and rotates pages of readings. You need ESP32 DevKit V1, BME280 Environmental Sensor, INA219 Current Monitor, MPU6050 IMU, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 4 steps and about 70 minutes.
- Level
- Intermediate
- Time
- About 70 min
- Parts
- 6
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- SensorsBuy
- SensorsBuyMPU6050 IMU × 1
- DisplaysBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| All SDA pins | ESP32 GPIO21 | Shared data line |
| All SCL pins | ESP32 GPIO22 | Shared clock line |
| All VCC / VIN | ESP32 3V3 | Power |
| All GND | ESP32 GND | Ground |
| INA219 VIN+ / VIN− | In series with a small load (for example an LED and 220 Ω from 3V3) | Current to measure |
Code
Libraries: Adafruit BME280, INA219, MPU6050 and SSD1306. Addresses used: OLED 0x3C, BME280 0x76, INA219 0x40, MPU6050 0x68: no clashes.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_INA219.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_SSD1306.h>
Adafruit_BME280 bme; Adafruit_INA219 ina; Adafruit_MPU6050 mpu;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
bool hasBme, hasIna, hasMpu;
int page = 0;
void scan() {
for (byte a = 1; a < 127; a++) { Wire.beginTransmission(a); if (Wire.endTransmission() == 0) Serial.printf("Found 0x%02X\n", a); }
}
void setup() {
Serial.begin(115200); Wire.begin(21, 22); scan();
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); oled.setTextColor(SSD1306_WHITE);
hasBme = bme.begin(0x76); hasIna = ina.begin(); hasMpu = mpu.begin(0x68);
}
void loop() {
oled.clearDisplay(); oled.setTextSize(1); oled.setCursor(0, 0);
if (page == 0) { oled.println("BME280 0x76"); if (hasBme) { oled.printf("%.1f C %.0f %%\n%.0f hPa", bme.readTemperature(), bme.readHumidity(), bme.readPressure() / 100); } else oled.print("missing"); }
if (page == 1) { oled.println("INA219 0x40"); if (hasIna) oled.printf("%.2f V\n%.1f mA", ina.getBusVoltage_V(), ina.getCurrent_mA()); else oled.print("missing"); }
if (page == 2) { oled.println("MPU6050 0x68"); if (hasMpu) { sensors_event_t a, g, t; mpu.getEvent(&a, &g, &t); oled.printf("x %.1f y %.1f\nz %.1f m/s2", a.acceleration.x, a.acceleration.y, a.acceleration.z); } else oled.print("missing"); }
oled.display();
page = (page + 1) % 3;
delay(2000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Found 0x3C Found 0x40 Found 0x68 Found 0x76
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Serial at start | Four addresses: 0x3C, 0x40, 0x68 and 0x76 |
| Unplug the MPU6050 and reset | Its page says "missing", the others still work |
| Tilt the board | MPU6050 z reading moves away from about 9.8 |
If it does not work
Scanner finds nothing
SDA and SCL swapped, or no common ground.
Two modules, one address
Change one with its address pin, for example BME280 SDO to 3V3 for 0x77.
Bus hangs with all four
Too many pull-ups in parallel; remove some on the modules or shorten wires.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the four sensors on one I²C bus?
ESP32 DevKit V1, BME280 Environmental Sensor, INA219 Current Monitor, MPU6050 IMU, SSD1306 OLED Display and Breadboard 830 Tie Points.
How long does the four sensors on one I²C bus take to build?
About 70 minutes for a intermediate maker, in 4 steps.
How do I know the four sensors on one I²C bus works?
Serial at start: Four addresses: 0x3C, 0x40, 0x68 and 0x76. Unplug the MPU6050 and reset: Its page says "missing", the others still work. Tilt the board: MPU6050 z reading moves away from about 9.8.
Scanner finds nothing: what should I check?
SDA and SCL swapped, or no common ground.
Two modules, one address: what should I check?
Change one with its address pin, for example BME280 SDO to 3V3 for 0x77.
Bus hangs with all four: what should I check?
Too many pull-ups in parallel; remove some on the modules or shorten wires.
