Projects / I2C bus with three sensors

I2C bus with three sensors

Intermediate45 minGuided buildReviewed

Build it step by step

0 of 6 done
  1. UNO16.8 mASSD1306

    Wire one device

    Add the OLED first and run the scanner.

  2. UNOBME28027.6°C

    Add the second

    Wire the BME280 and run the scanner again.

  3. UNOBH1750706 lux

    Add the third

    Wire the BH1750 and note all three addresses.

  4. UNOBH1750706 lux

    Read each sensor

    Check the Serial Monitor values for temperature, humidity and light.

  5. UNO16.8 mASSD1306

    Show them together

    Watch all four values on the OLED.

  6. UNOBH1750708 lux

    Force a clash

    Set the BH1750 ADDR pin high and see its address change to 0x5C.

In short

How do you build an I2C bus with three sensors?

Put an OLED, a BME280 and a light sensor on one I2C bus and read them all. You need Arduino Uno R3, SSD1306 OLED Display, BME280 Environmental Sensor, BH1750 light sensor, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 45 minutes.

Level
Intermediate
Time
About 45 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Uno 5VOLED, BME280 and BH1750 VCCPower (check each board accepts 5 V, otherwise use 3V3)
Uno GNDOLED, BME280 and BH1750 GNDGround
Uno A4 (SDA)All three SDA pinsShared data
Uno A5 (SCL)All three SCL pinsShared clock

Code

Arduino IDE, board "Arduino Uno". Install "Adafruit BME280 Library" with "Adafruit Unified Sensor", "BH1750" by Christopher Laws and "U8g2". The BME280 address is 0x76 or 0x77 depending on its SDO pin, and the BH1750 is 0x23 (0x5C if its ADDR pin is pulled high). If two devices share an address, change one with its address pin.

Runs on a virtual Arduino Uno 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 <BH1750.h>
#include <U8x8lib.h>

U8X8_SSD1306_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE);
Adafruit_BME280 bme;
BH1750 light;

void scan() {                              // step 1: print every address found
  Serial.println("Scanning...");
  for (byte a = 1; a < 127; a++) {
    Wire.beginTransmission(a);
    if (Wire.endTransmission() == 0) { Serial.print("Found 0x"); Serial.println(a, HEX); }
  }
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  scan();                                  // expect 0x23 (BH1750), 0x3C (OLED), 0x76 or 0x77 (BME280)
  if (!bme.begin(0x76) && !bme.begin(0x77)) Serial.println("BME280 not found");
  light.begin();
  oled.begin();
  oled.setFont(u8x8_font_chroma48medium8_r);
}

void loop() {
  char b[17], v[8];
  dtostrf(bme.readTemperature(), 5, 1, v); snprintf(b, sizeof b, "Temp %s C ", v); oled.drawString(0, 1, b);
  dtostrf(bme.readHumidity(), 5, 1, v);    snprintf(b, sizeof b, "Hum  %s %% ", v); oled.drawString(0, 3, b);
  dtostrf(bme.readPressure() / 100.0, 6, 0, v); snprintf(b, sizeof b, "Pres %s hPa", v); oled.drawString(0, 5, b);
  snprintf(b, sizeof b, "Lux %u     ", (unsigned)light.readLightLevel()); oled.drawString(0, 7, b);
  delay(1000);
}

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 Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Scanning...
Found 0x3C
Found 0x76

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
ScannerLists 0x23, 0x3C and 0x76 or 0x77
Finger over the BH1750Lux drops
Breath on the BME280Humidity rises
Unplug one deviceIt disappears from the scan

If it does not work

Scanner finds nothing

Check SDA on A4, SCL on A5 and the power pins.

BME280 not found

Try the other address or check its VCC level.

OLED blank

Check 0x3C appears in the scan and the display wiring.

Values freeze

A loose wire has stopped the bus. Check all joints.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the I2C bus with three sensors?

Arduino Uno R3, SSD1306 OLED Display, BME280 Environmental Sensor, BH1750 light sensor, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the I2C bus with three sensors take to build?

About 45 minutes for a intermediate maker, in 6 steps.

How do I know the I2C bus with three sensors works?

Scanner: Lists 0x23, 0x3C and 0x76 or 0x77. Finger over the BH1750: Lux drops. Breath on the BME280: Humidity rises.

Scanner finds nothing: what should I check?

Check SDA on A4, SCL on A5 and the power pins.

BME280 not found: what should I check?

Try the other address or check its VCC level.

OLED blank: what should I check?

Check 0x3C appears in the scan and the display wiring.

Values freeze: what should I check?

A loose wire has stopped the bus. Check all joints.