Capstone · #16 of 20
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:- SHT31: Temperature + humidity, 0x44 address
- BME280: Temperature + humidity + pressure, 0x76 or 0x77
- SHT40: Temperature + humidity, improved accuracy
<h3>I²C Wiring</h3>
Standard I²C connections:
<ul>
<li><strong>VCC</strong> → 3.3V (not 5V!)</li>
<li><strong>GND</strong> → GND</li>
<li><strong>SDA</strong> → GPIO21 (or configured pin)</li>
<li><strong>SCL</strong> → GPIO22 (or configured pin)</li>
<li><strong>Pull-ups</strong>: 10kΩ resistors on SDA and SCL to 3.3V</li>
</ul>
<h3>Address Scanning</h3>
First step: verify sensor is connected:
<ol>
<li>Scan I²C bus for all addresses (0x08–0x77)</li>
<li>Look for ACK responses</li>
<li>Verify expected address matches datasheet</li>
</ol>
<h3>Common Issues</h3>
<ul>
<li><strong>No device found</strong>: Check wiring, pull-ups, power</li>
<li><strong>Wrong address</strong>: Some sensors have address-select pins</li>
<li><strong>NACK errors</strong>: Sensor not ready, check timing</li>
</ul>
Demo
Sensor wiring is physical, not visual. Review this before connecting your sensor.
Key takeaways
- Use 3.3V sensors (not 5V) for direct ESP32 connection
- I²C requires pull-up resistors (10kΩ) on SDA and SCL
- Always scan I²C bus to verify sensor address
- Check datasheet for address-select pins if address doesn’t match
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