← all lessons
Capstone · #16 of 48

Sensor Selection + I²C Wiring

SHT31/BME280 Integration

Why it matters

The capstone uses an I²C environmental sensor (temperature, humidity, pressure). Proper wiring and address scanning are critical.

The idea

Sensor Options

Common I²C environmental sensors:

I²C Wiring

Standard I²C connections:

Address Scanning

First step: verify sensor is connected:

  1. Scan I²C bus for all addresses (0x08–0x77)
  2. Look for ACK responses
  3. Verify expected address matches datasheet

Common Issues

Demo

Sensor wiring is physical, not visual. Review this before connecting your sensor.

Key takeaways

Going deeper

SHT31 has excellent accuracy (±2% RH, ±0.3°C) and low power consumption (~2.7mA active, <1µA sleep). BME280 adds pressure sensing but uses more power. For battery-powered devices, SHT31 is often the better choice. Always check sensor power consumption in datasheet.

Math details

I²C pull-up calculation:
  V_CC = 3.3V
  I_max = 3mA (I²C spec)
  R_min = V_CC / I_max = 3.3V / 0.003A = 1100Ω

  Use 10kΩ (standard value, provides ~330µA current)

Capacitance limit:
  C_bus_max = 400pF (I²C spec)
  With 10kΩ pull-ups: works up to ~1m cable length

Sensor power:
  SHT31: 2.7mA active, <1µA sleep
  BME280: 3.6µA sleep, 338µA active

Implementation

LLM Prompt: I²C Address Scanner

Write Rust code for ESP32 I²C address scanner using esp-hal.
Scan addresses 0x08–0x77, attempt read/write, report which addresses
respond with ACK. Include timeout handling and error reporting.
Useful for debugging I²C connections.

Lab Exercise

  1. Connect SHT31: VCC→3.3V, GND→GND, SDA→GPIO21, SCL→GPIO22
  2. Add 10kΩ pull-ups on SDA and SCL to 3.3V
  3. Run I²C address scanner — verify sensor at 0x44
  4. Read temperature register — verify reasonable values
  5. Read humidity register — verify 0–100% range

full glossary →