The Sensing Principle: How Temperature Sensors Actually Work
At the component level, analog temperature sensors and thermistors rely on two entirely different physical phenomena. NTC (Negative Temperature Coefficient) thermistors are made from sintered semiconductor ceramics; as thermal energy increases, more charge carriers are freed, causing resistance to drop in a highly non-linear, exponential curve. Silicon bandgap sensors, like the TMP36, exploit the predictable temperature coefficient of a silicon PN junction’s forward voltage drop, yielding a highly linear analog voltage output that scales directly with absolute temperature.
Digital sensors, such as the DS18B20, encapsulate a silicon bandgap sensing element alongside an internal ADC, calibration memory, and a 1-Wire communication state machine. Instead of outputting a raw voltage susceptible to wire resistance and noise, the sensor digitizes the thermal reading on-die and transmits a serialized digital packet. This fundamental difference—measuring resistance/voltage versus reading a digital register—dictates everything about your wiring, math, and noise immunity.
Decision Tree: Which Sensor Architecture to Pick
Do not waste time guessing which sensor fits your project. Use this decision matrix to terminate your part selection immediately based on your physical constraints and microcontroller platform.
| Project Constraint | If you need... | Then choose... |
|---|---|---|
| Ultra-fast thermal response (<1s) and custom probe geometries | Bare die or glass-bead exposure, minimal thermal mass | 10k NTC Thermistor |
| Simple analog read on a 5V Arduino Uno, short wires (<1m) | Linear voltage output, no external libraries, basic precision (±2°C) | TMP36 Analog IC |
| Long cable runs (up to 100m), multi-drop bus, ESP32/Raspberry Pi | Immunity to voltage drop, digital bus, high precision (±0.5°C) | DS18B20 (Default Pick) |
Wiring and Pinout: Supply Ranges and Connections
Proper power delivery and pull-up configuration are where most sensor projects fail on the bench. Below is the exact wiring specification for a standard 3.3V microcontroller environment.
| Sensor Model | Supply Range (VCC) | Output Type | Required External Components | Pinout (Flat face towards you) |
|---|---|---|---|---|
| 10k NTC Thermistor | 3.3V or 5.0V | Variable Resistance | 10kΩ precision pull-down resistor (voltage divider) | Leads are non-polarized |
| TMP36 | 2.7V to 5.5V | Analog Voltage | 100nF decoupling capacitor across VCC/GND | 1: VCC, 2: VOUT, 3: GND |
| DS18B20 | 3.0V to 5.5V | Digital (1-Wire) | 4.7kΩ pull-up resistor on Data line to VCC | 1: GND, 2: DQ (Data), 3: VDD |
Output Signal Math: Raw Readings to Physical Units
A raw ADC integer or a 16-bit register dump is useless until you apply the correct transfer function. Here is the exact math to convert raw microcontroller readings into degrees Celsius. We are assuming a 12-bit ADC (0-4095) for the analog example, typical of modern ARM and ESP32 chips.
TMP36 (Analog Voltage Output)
The TMP36 outputs a linear voltage with a 500mV offset and a scale factor of 10mV/°C. The output is strictly an analog voltage; it is not a digital stream.
// Assuming 3.3V logic and a 12-bit ADC (0-4095)
float adc_voltage = (analogRead(TMP36_PIN) * 3.3) / 4095.0;
float temp_c = (adc_voltage - 0.5) * 100.0;
DS18B20 (Digital 1-Wire Output)
The DS18B20 outputs a 16-bit signed integer via the 1-Wire protocol. In its default 12-bit resolution mode, the 4 least significant bits represent the fractional degrees. The math is a simple bit-shift or division.
// Raw 16-bit signed integer read from the sensor scratchpad
int16_t raw_temp = (data[1] << 8) | data[0];
float temp_c = raw_temp / 16.0; // Converts 4-bit fraction to decimal
10k NTC Thermistor (Resistance Output)
Thermistors require the Steinhart-Hart equation to map the non-linear resistance to temperature. First, calculate the resistance from your voltage divider, then apply the coefficients (typically provided in the manufacturer's datasheet).
// Voltage divider: VCC -> 10k Fixed -> ADC -> NTC -> GND
float raw = analogRead(NTC_PIN);
float resistance = 10000.0 * ((4095.0 / raw) - 1.0);
// Steinhart-Hart simplified (B-parameter equation, B=3950)
float temp_k = 1.0 / ( (1.0/298.15) + (log(resistance/10000.0)/3950.0) );
float temp_c = temp_k - 273.15;
Common Interference Sources and Calibration Fixes
When your serial monitor spits out jittery or drifting numbers, the sensor is rarely broken. The issue is almost always environmental interference. Here is how to diagnose and fix the three most common failure modes.
- 50/60Hz Mains Hum (Analog Sensors): High-impedance analog traces act as antennas. If your TMP36 or NTC wiring runs parallel to AC mains cables, capacitive coupling will inject 50/60Hz noise into your ADC. Fix: Use shielded twisted-pair cable for analog runs over 1 meter, and implement a software moving-average filter (e.g., averaging 20 consecutive samples).
- Parasitic Capacitance on 1-Wire (DS18B20): The 1-Wire protocol relies on an open-drain architecture. If you use a long CAT5 cable for a waterproof DS18B20 probe, the cable's parasitic capacitance slows the rising edge of the data signal, causing CRC checksum failures. Fix: Drop the 4.7kΩ pull-up resistor to 2.2kΩ or 1kΩ for cable runs exceeding 10 meters to provide more current to charge the cable capacitance.
- Self-Heating (NTC Thermistors): Pushing too much current through a small glass-bead NTC will cause it to heat itself, reading 1-2°C higher than ambient. Fix: Keep the voltage divider current below 100µA, or pulse the VCC power to the divider only during the exact millisecond you take the ADC reading.
The Verdict: Default to the DS18B20
For 95% of embedded maker projects, environmental monitors, and home automation builds, the DS18B20 is the definitive choice. Stop fighting ESP32 ADC non-linearity and analog voltage drops over long wires. The DS18B20 provides factory-calibrated ±0.5°C accuracy, requires only a single GPIO pin (which can be shared by dozens of sensors on the same bus), and completely bypasses the need for complex Steinhart-Hart floating-point math on your microcontroller.
Buy the Maxim/Analog Devices DS18B20+ (TO-92 package) for PCB integration, or the Adafruit 381 (waterproof stainless steel probe) for liquid and outdoor environmental sensing. Wire it with a 4.7kΩ pull-up, use the standard OneWire and DallasTemperature libraries, and divide the raw 16-bit register by 16.0. Your temperature data will be rock-solid from the first boot.






