Sensor Selection + I²C Wiring
From Physical Question to Address Scan
The capstone board wakes from deep sleep, samples the room, and decides whether the enclosure is healthy. The firmware wants a number. The world does not provide numbers. It provides humidity on a polymer film, temperature through a package, pressure on a membrane, light on a junction, and noise from every wire nearby.
Choosing a sensor is choosing how the physical world becomes bits.
The old beginner move is to search for "I2C temperature sensor" and buy the first board that appears. The engineering move is slower: define the measurement, choose the sensor whose limits match it, wire the bus so edges are real, then prove the device is present with an address scan before trusting any reading.
By the end, you can
- Start sensor selection from the physical quantity, range, accuracy and update rate
- Read power, sleep current, conversion time, address and interface constraints from a datasheet
- Wire an I2C sensor to 3.3 V logic with SDA, SCL, shared ground and pull-ups
- Explain why cable length, connector count and bus capacitance slow I2C rising edges
- Use an address scan to separate wiring faults from firmware parsing faults
- Plan a low-power sample cycle for a sleeping environmental node
The measurement comes first
Before part numbers, write the sentence the product needs answered:
Is the sealed electronics enclosure staying inside its safe temperature and humidity range between radio uploads?
That sentence already rules out bad choices. A fast accelerometer is irrelevant. A temperature-only probe may miss humidity condensation. A gorgeous high-accuracy sensor that never sleeps may ruin the battery budget. The physical question defines the measurement chain.
For a simple environmental capstone, common candidates include:
- SHT31 or SHT40: temperature and humidity, accurate, I2C, good for battery nodes.
- BME280: temperature, humidity and pressure, useful when pressure matters too.
- DS18B20: temperature probe, excellent when the sensing point is away from the board.
- NTC thermistor: cheap analog temperature, but needs calibration and ADC care.
Board placement is part of the sensor
The sensor does not read "the room." It reads its own die or sensing element. If the sensor sits next to a warm regulator, it reads the regulator's weather. If it sits in dead air inside an enclosure, it lags the outside environment. If the PCB copper pours connect it to a heater, the layout becomes part of the error term.
For the capstone, the useful habit is to log three things with every reading:
- The raw sensor value.
- The board state: asleep, just woke, radio active or charging.
- The time since wake and time since last radio transmit.
Those extra columns tell you when the sensor is measuring the environment and when it is measuring your own electronics.
I2C wiring is a shared bus, not point-to-point magic
I2C uses two signal lines: SDA for data and SCL for clock. Both are open-drain. Devices pull a line low, but nobody drives it high directly. Pull-up resistors to the logic rail restore the high level.
That means the wiring has four essential connections:
VCCto the correct sensor supply, usually 3.3 V for direct ESP32 wiring.GNDto the same ground reference as the ESP32.SDAto the configured SDA GPIO.SCLto the configured SCL GPIO.- Pull-ups from SDA and SCL to 3.3 V, unless the module already provides suitable ones.
Why does an I2C bus need pull-up resistors?
-
Correct. Open-drain devices only pull low. The resistors create the high level.
-
Addresses are inside the devices or address-select pins, not created by pull-ups.
-
SPI is a different bus with different signal roles.
-
Pull-ups define the high level. A 5 V pull-up would actually be unsafe for a 3.3 V-only pin.
Rise time is the hidden wiring bug
The I2C falling edge is easy: a device turns on a transistor and pulls the line low. The rising edge is passive: the pull-up resistor charges all the bus capacitance. More wire, more modules and more connector metal all add capacitance. Too much capacitance or too weak a pull-up makes the signal rise slowly, so the receiver sees a rounded edge instead of a clean logic high.
Use the pull-up explorer below. The same bus can pass at 100 kHz and fail at 400 kHz. That is not a software mystery. It is edge timing.
- Rise time tr
- 398 ns
- Spec limit
- 300 ns
- Rise verdict
- FAIL
- Sink current Isink
- 0.70 mA
Try these moves:
- Set the bus to 100 kHz and try a 10 kΩ pull-up with 100 pF bus capacitance.
- Move to 400 kHz without changing the wiring.
- Increase bus capacitance toward 400 pF and watch the edge fail.
- Lower the pull-up. Notice that sink current rises while rise time improves.
The address scan is your first bring-up test
Before parsing temperature registers, prove the device answers. An I2C scanner sends an address and records whether any device ACKs. If nothing ACKs, you have a physical or bus configuration problem. If the expected address ACKs but the reading is nonsense, now you debug register protocol, conversion timing or driver code.
The common environmental addresses are easy to remember only until the board changes:
SHT31 often appears at 0x44 or 0x45; BME280 often appears at 0x76 or 0x77.
Modules may expose an address-select solder jumper. Two devices with the same fixed
address cannot share one I2C bus unless you add a mux, switch one device off, or choose
a different part.
Power is part of the measurement schedule
A sleeping environmental node should not leave every sensor awake all day unless the budget says it can. Some sensors have a low-current sleep mode. Some can be powered from a switched rail or MOSFET. Some need a conversion delay after wake before the first reading is valid.
For the capstone, the sample cycle should read like a small state machine:
- Wake the ESP32 from deep sleep.
- Power or wake the sensor.
- Wait the datasheet conversion time.
- Read and sanity-check the value.
- Store the reading in RTC memory or flash policy.
- Decide whether to transmit now or batch the data.
- Put the sensor and ESP32 back to sleep.
A pull-up value is bounded from both sides
Too large a pull-up makes the rising edge slow because the RC time constant is large. Too small a pull-up makes every LOW expensive and may exceed the device's allowed sink current. The rough lower bound is set by the maximum LOW current:
At 3.3 V and a 3 mA sink limit, is about 1.1 kΩ. The upper bound comes from rise time and bus capacitance. In practice, 4.7 kΩ is a common starting point for short 3.3 V buses, while long cables or 400 kHz operation often need a lower value or a different wiring plan.
Your scanner finds 0x76, but the code was written for an SHT31 at 0x44. What is
the first conclusion?
Show worked solution
The bus is alive, but the expected device is probably not what is connected. 0x76 is
common for BME280-like boards. Check the module label, address-select jumper and driver.
Do not debug temperature-register parsing until the address matches the intended part.
A short prototype works at 100 kHz with 10 kΩ pull-ups. After adding a cable and a second sensor, 400 kHz reads fail intermittently. Name two likely electrical fixes.
Show worked solution
The added wiring likely increased bus capacitance and slowed the rising edge. Lower the pull-up value while keeping sink current within device limits, shorten or improve the wiring, reduce bus speed, split the bus, or use an I2C buffer if the physical span must stay long.
Key takeaways
- Choose a sensor from the physical measurement: range, accuracy, update rate, power, package and placement.
- I2C wiring needs SDA, SCL, 3.3 V, ground and suitable pull-ups to the correct logic rail.
- Bus capacitance and pull-up resistance set rise time, so wiring changes can break a bus that used to work.
- Address scanning is the first bring-up test because it separates physical presence from register-level code.
- A low-power sensor node needs a measurement schedule: wake, settle, read, store, maybe transmit, then sleep.
A sensor is not the tiny square on a breakout. It is the whole path from the physical world to a number the firmware can trust. Choose that path deliberately, wire the bus so the edges are real, and prove the address before believing the data. The next lesson turns those facts into firmware architecture.