If you are interfacing sensors temp modules with an ESP32 or Arduino, bypass analog voltage-output sensors for any critical application and use a digital 1-Wire or I2C sensor. Microcontroller ADCs—especially the ESP32’s notoriously non-linear analog-to-digital converter—introduce severe measurement drift when reading raw analog voltages over varying wire lengths. For 90% of maker and IoT projects, the DS18B20 1-Wire digital sensor is the definitive default choice because it performs the analog-to-digital conversion on the silicon die, outputting a noise-immune digital word directly to your GPIO.

The Physics of Temperature Transducers

Analog sensors like the TMP36 rely on a proportional-to-absolute-temperature (PTAT) circuit. This design measures the voltage drop across a bipolar transistor pair; as thermal energy increases, the base-emitter voltage shifts predictably, outputting a continuous analog voltage. Digital sensors, conversely, embed a micro-machined thermal diode alongside a silicon bandgap reference and an on-chip ADC.

Advanced environmental modules like the BME280 use CMOS-based Sigma-Delta ADCs to achieve high resolution without the thermal drift inherent in simple op-amp circuits. Because the analog-to-digital conversion happens millimeters from the sensing die inside the package, digital sensors output discrete binary words (via 1-Wire or I2C) rather than a continuous voltage, entirely bypassing the voltage-drop and noise vulnerabilities of long wire runs.

Wiring and Pinout Specifications

Before wiring, verify your microcontroller's logic level. The ESP32 is strictly 3.3V on its GPIO pins; feeding 5V into an ESP32 data pin will destroy the silicon. The Arduino Uno is 5V tolerant but requires logic-level shifting if connected to 3.3V I2C sensors.

Sensor Module Interface Supply Range (VCC) Key Pins Pull-up Required?
TMP36 Analog Voltage 2.7V to 5.5V VCC, GND, VOUT No (Direct to ADC)
DS18B20 Digital 1-Wire 3.0V to 5.5V VDD, GND, DQ Yes (4.7kΩ to VCC)
BME280 I2C / SPI 1.71V to 3.6V VIN, GND, SCL, SDA Yes (Usually on breakout)
Wiring Warning: When using the DS18B20 in parasitic power mode (connecting VDD to GND), the 4.7kΩ pull-up resistor is insufficient to supply the required 1.5mA during temperature conversions. Always use standard VDD power mode for reliable readings on ESP32 builds.

Output Signal Math: Raw Reading to Physical Units

Understanding what the output actually is—and the math required to scale it to Celsius—is where most hobbyist code fails. Here is the raw-to-unit math for the two most common architectures.

1. TMP36 (Analog Voltage Output)

The TMP36 outputs a DC voltage scaled at 10mV per degree Celsius, with a 500mV offset to accommodate negative temperatures. The formula is: Temp(°C) = (Vout - 0.5) / 0.01.

On an ESP32 (12-bit ADC, 3.3V reference), reading the raw ADC value requires scaling. However, the Espressif ESP32 ADC documentation explicitly warns that the raw ADC curve is non-linear, particularly near 0V and 3.3V. You must use the ESP-IDF ADC calibration API or accept a ±2°C error margin.

// Idealized TMP36 Math (Arduino Uno 5V / 10-bit ADC)
int raw = analogRead(A0);
float voltage = (raw / 1023.0) * 5.0;
float tempC = (voltage - 0.5) * 100.0;

2. DS18B20 (Digital 1-Wire Output)

The DS18B20 outputs a 16-bit two's complement digital word. In its default 12-bit resolution mode, the least significant bit (LSB) represents 0.0625°C. There is no voltage scaling required; you simply multiply the raw integer by the resolution factor.

// DS18B20 Raw 16-bit Math (Bypassing DallasTemperature library bloat)
// data[0] = LSB, data[1] = MSB
int16_t raw = (data[1] << 8) | data[0];
float tempC = raw * 0.0625;

Signal Integrity, Calibration, and Interference

Every sensor type has distinct failure modes and interference vulnerabilities on the workbench.

  • Analog Interference (TMP36): Analog wires act as antennas. A 2-meter run of 22 AWG wire near a mains-powered inverter will induce 50/60Hz hum, causing the ADC reading to fluctuate wildly. Fix: Add a 0.1µF ceramic bypass capacitor directly across the VCC and GND pins of the sensor, and twist the signal wire with the ground return.
  • I2C Bus Capacitance (BME280): I2C was designed for on-board communication, not long cables. The I2C specification limits bus capacitance to 400pF. Using standard jumper wires longer than 30cm will cause signal rise-time degradation, resulting in I2C timeouts and corrupted registers. Fix: Use an active I2C bus extender (like the P82B96) for runs over 1 meter.
  • 1-Wire Timing Jitter (DS18B20): The 1-Wire protocol relies on strict microsecond timing. On an ESP32 running FreeRTOS, background WiFi tasks can interrupt the bit-banging routine, causing CRC check failures. Fix: Use a hardware UART-based 1-Wire master or ensure your software library disables interrupts during the read sequence.
Calibration Note: According to the Analog Devices DS18B20 Datasheet, the sensor is factory laser-trimmed to ±0.5°C accuracy from -10°C to +85°C. The TMP36 Datasheet specifies ±2°C accuracy at 25°C. If you require tighter tolerances with the TMP36, you must perform a manual two-point offset calibration in software using an ice bath and boiling water reference.

Decision Tree: Which Sensor Temp Module to Buy

Use this decision path to select the correct sensor for your specific physical environment and microcontroller constraints.

Project Constraint If True, Choose... Why?
Must submerge in liquid, bury in soil, or mount outdoors DS18B20 (Waterproof Probe) Stainless steel housing prevents corrosion; digital signal ignores moisture-induced leakage currents.
Need ambient room temp + humidity + barometric pressure on a short PCB trace BME280 (I2C Breakout) Highly integrated CMOS MEMS; provides three environmental data points on a single I2C address.
Building a basic 5V Arduino Uno educational kit with no digital libraries TMP36 (Analog) Requires zero protocol libraries; outputs raw voltage readable by basic multimeter and simple ADC code.
Running sensor cables > 3 meters through a noisy industrial/automotive environment DS18B20 (Digital) 1-Wire digital pulses reject EMI that would completely destroy an analog TMP36 voltage signal.

The Final Verdict: Your Default Pick

If your project does not strictly require barometric pressure (ruling out the BME280) and you are building a functional IoT node rather than a basic 5V learning toy (ruling out the TMP36), there is one definitive component to standardize your bill of materials on.

Default Recommendation: Buy the Maxim Integrated (Analog Devices) DS18B20+ in a waterproof stainless steel probe assembly (e.g., Adafruit Product ID 381 or equivalent generic waterproof probes).

Why this is the ultimate pick: It entirely eliminates the ESP32 ADC non-linearity headache, requires only a single GPIO pin (leaving your I2C bus free for displays or IMUs), and the physical stainless steel probe survives condensation, soil acidity, and accidental drops that would instantly shatter a bare TO-92 TMP36 or a fragile BME280 breakout board. Pair it with a standard 4.7kΩ pull-up resistor and the OneWire library, and you will achieve reliable, drift-free ±0.5°C accuracy across wire runs up to 15 meters.