If you are building an ESP32 or Arduino project and need to measure the physical world, your default environmental sensor should be the Bosch BME280 (I2C), and your default liquid/probe sensor should be the Dallas DS18B20 (1-Wire). When evaluating the various types of sensors available on the market, the sheer volume of breakout boards can paralyze decision-making. This guide cuts through the catalog noise, breaking down the exact electrical outputs, the raw-to-unit math required to interface them, and a hard decision tree to terminate your part selection.

The Core Transduction Principle

Sensors are fundamentally transducers that convert a physical phenomenon—such as thermal energy, mechanical stress, or photon flux—into a measurable electrical property, usually resistance, capacitance, or a piezoelectric charge. In a microcontroller circuit, we cannot measure resistance directly; instead, we pass a known reference current or voltage through this variable component to create a proportional voltage drop or charge accumulation.

This resulting analog signal is then either read directly by the microcontroller’s Analog-to-Digital Converter (ADC) or processed by an onboard Application-Specific Integrated Circuit (ASIC). The ASIC digitizes the signal, applies internal calibration curves, and transmits the final value via a serial protocol like I2C or SPI. Understanding whether your sensor outputs a raw analog ratio or a calibrated digital packet dictates your entire wiring, power budget, and code architecture.

Analog vs. Digital: What the Output Actually Is

A critical mistake beginners make is conflating analog and digital outputs. They are electrically distinct and suffer from entirely different failure modes.

Callout: The Output Reality Check
Analog (Voltage/Current): The output is a continuous electrical level (e.g., 0–3.3V or 4–20mA). The microcontroller must sample this voltage and scale it.
Digital (Serial): The output is a stream of discrete logic-level bytes (e.g., I2C, SPI, UART). The physical measurement is encoded in binary; the microcontroller reads registers, not voltages.

Common Interference Sources

  • Analog Sensors: Highly susceptible to Electromagnetic Interference (EMI). A 10k NTC thermistor running 2 meters alongside a 120V AC mains line will pick up 60Hz hum, causing the ADC reading to oscillate wildly. Long wires also introduce voltage drop and parasitic resistance, skewing the reading.
  • Digital Sensors: Immune to amplitude noise, but highly susceptible to bus capacitance and timing jitter. An I2C bus running at 400kHz (Fast Mode) will fail if the wire capacitance exceeds 400pF (roughly 30cm of standard ribbon cable) unless you lower the pull-up resistor values to drive the edges harder.

Wiring and Pinout Reference for ESP32/Arduino

Below is the benchmark wiring table for the most common sensor archetypes. Always verify the supply range; feeding a 3.3V I2C sensor 5V from an Arduino Uno will permanently brick the internal ASIC.

Sensor / Type Protocol Supply Range Data Pin(s) Critical Wiring Notes
BME280 (Env) I2C / SPI 1.71V – 3.6V SDA / SCL Requires 2.2kΩ pull-ups on SDA/SCL for 400kHz operation.
DS18B20 (Probe) 1-Wire 3.0V – 5.5V DQ (Data) Mandatory 4.7kΩ pull-up on DQ to VCC. Do not use parasitic power mode on long runs.
10k NTC (Analog) Analog V 3.3V / 5.0V ADC Pin Must be wired as a voltage divider with a 10kΩ 1% reference resistor.
MPX5700AP (Press) Analog V 4.75V – 5.25V Vout Outputs up to 4.5V. Requires a voltage divider if interfacing with a 3.3V ESP32 ADC.

Output Signal Math: Raw Readings to Physical Units

Digital sensors like the BME280 handle the complex calculus internally; you simply read the compensated registers via the Bosch Sensortec API. However, when using analog types of sensors like an NTC thermistor, you must perform the raw-to-unit math in your firmware.

The ESP32 ADC Gotcha

The ESP32 features a 12-bit ADC (0–4095 raw), but it is notoriously non-linear near the 0V and 3.3V rails. According to the Espressif ADC documentation, you must configure the ADC to 11dB attenuation and design your voltage divider so the expected readings fall strictly between 0.15V and 2.5V (roughly 180 to 3100 raw) to maintain ±100mV accuracy.

Raw-to-Unit Math: 10k NTC Thermistor

Assuming a 3.3V supply, a 10kΩ reference resistor ($R_{ref}$), and an ESP32 12-bit ADC reading:

  1. Calculate Voltage: $V_{out} = (ADC_{raw} / 4095.0) \times 3.3$
  2. Calculate Thermistor Resistance: $R_{ntc} = R_{ref} \times \frac{V_{out}}{3.3 - V_{out}}$
  3. Apply Steinhart-Hart Equation: To scale resistance to Kelvin, use the formula $1/T = A + B \ln(R) + C (\ln(R))^3$. For a standard 10k 3950 NTC, the coefficients are roughly $A = 0.001129$, $B = 0.000234$, and $C = 0.000000087$. (For deeper component-level math, refer to this All About Circuits NTC guide).
  4. Convert to Celsius: $T_{celsius} = (1 / T_{kelvin}) - 273.15$
Calibration Note: The Steinhart-Hart coefficients provided above are generic. For precision work (±0.2°C), you must calibrate your specific thermistor batch by measuring its resistance in an ice bath (0°C) and boiling water (100°C at sea level), then solving the three simultaneous equations to find your exact A, B, and C values.

Decision Tree: Picking the Exact Sensor Part Number

Stop browsing random breakout boards. Use this decision matrix to terminate your search based on your physical and electrical constraints.

Application Need Environment / Constraints Concrete Part Pick
Ambient Temp, Humidity, Barometric Pressure Indoor / Low EMI / Short I2C runs Bosch BME280 (I2C)
Liquid, Pipe, or Probe Temperature High EMI / Long wire runs (up to 100m) Dallas DS18B20 (1-Wire)
High-Speed Vibration, Tilt, or Gyro Mechanical noise / Requires high sample rate InvenSense MPU-6050 (I2C)
High-Resolution Barometric (Altimetry) Outdoor / Drones / Weather stations Bosch BMP390 (SPI/I2C)
Industrial Pressure / Flow (4-20mA) Factory floor / Extreme EMI Any 4-20mA loop + 250Ω shunt

The Default Workbench Recommendation

There is no "it depends" when stocking your primary workbench inventory. If you are prototyping an IoT environmental monitor, weather station, or HVAC controller, buy the Bosch BME280. It provides temperature, humidity, and pressure in a single 2.5 x 2.5mm LGA package, draws microamps in sleep mode, and its I2C interface completely bypasses the ESP32's ADC non-linearity headaches.

If your project requires measuring the temperature of a liquid, a motor stator, or anything outside the immediate ambient air of the PCB, buy the waterproof DS18B20 probe. Its 1-Wire digital protocol guarantees that the 60Hz hum from nearby AC compressors or VFDs will not corrupt your temperature readings, a guarantee no analog thermistor can make. Wire them according to the tables above, respect the pull-up resistor requirements, and your firmware will read clean, physical-unit data on the first compile.