If you are building an environmental monitor, a 3D printer enclosure, or a battery management system in 2026, picking the right temperature sensor dictates your wiring complexity, code overhead, and ultimate accuracy. For 90% of hobbyist and IoT builds, the DS18B20 (digital, 1-Wire) or BME280 (digital, I2C) are the default picks, but analog types like the TMP36 still win for ultra-low-cost, simple ADC reads. This guide cuts through the datasheet jargon to give you the exact raw-to-unit math, wiring constraints, and a final decision matrix so you can stop debating and start soldering.
The Sensing Principle: How Solid-State ICs Measure Heat
Solid-state temperature sensors rely on the predictable temperature dependence of a silicon PN junction's forward voltage drop. As temperature increases, the base-emitter voltage ($V_{BE}$) of an internal transistor decreases at a highly linear rate of approximately -2 mV/°C. This physical property of silicon is the foundation for almost every modern IC temp sensor on the market.
Inside the IC package, an internal amplifier scales this tiny millivolt shift into a usable output. Analog sensors output a continuous DC voltage proportional to this scaled shift, while digital sensors route the amplified signal through an internal ADC, apply factory calibration offsets, and serialize the data over protocols like I2C, SPI, or 1-Wire.
Analog vs. Digital: Output Signals and Raw-to-Unit Math
The most common mistake makers make is conflating analog voltage outputs with digital serial outputs. They require entirely different microcontroller peripherals and mathematical scaling.
Analog Output (e.g., TMP36, LM35)
What the output is: A continuous DC voltage, typically ranging from 0.1V to 2.0V.
Calibration/Scaling: Highly dependent on your microcontroller's ADC reference voltage. If your Arduino's USB line sags to 4.8V instead of 5.0V, your temperature reading will skew by nearly 2°C unless you use an internal 1.1V reference.
The Raw-to-Unit Math (TMP36):
- Step 1 (Raw to Voltage): $V_{out} = (ADC_{raw} \times V_{ref}) / 1024$ (for a 10-bit ADC)
- Step 2 (Voltage to Celsius): $Temp (°C) = (V_{out} - 0.5) \times 100$
analogReference(INTERNAL), or on an ESP32, use analogReadMilliVolts() to let the factory-calibrated eFuse handle the scaling.Digital Output (e.g., DS18B20, MCP9808, BME280)
What the output is: A serialized digital bitstream (I2C, SPI, or 1-Wire).
Calibration/Scaling: Handled entirely inside the silicon. The IC is laser-trimmed at the factory. You do not need to worry about VCC sag affecting the reading, as long as VCC stays within the IC's operating window.
The Raw-to-Unit Math (DS18B20 12-bit resolution):
- The IC returns a 16-bit two's complement integer.
- $Temp (°C) = Raw_{integer} \times 0.0625$
According to the Analog Devices DS18B20 datasheet, a raw hex value of 0x0550 (1360 in decimal) multiplied by 0.0625 yields exactly 85.0°C.
Wiring and Pinout Reference for Common Temp Sensor Types
Before you order parts, verify your microcontroller's logic level. ESP32 and Raspberry Pi Pico are strictly 3.3V logic devices; feeding 5V into their I2C or 1-Wire pins will destroy the GPIO matrix.
| Part Number | Protocol | Supply Range | Pins Required | Pull-up Resistor? |
|---|---|---|---|---|
| TMP36 | Analog | 2.7V - 5.5V | VCC, GND, Vout | No |
| LM35 | Analog | 4.0V - 30V | VCC, GND, Vout | No |
| DS18B20 | 1-Wire | 3.0V - 5.5V | VCC, GND, DQ | Yes (4.7kΩ to VCC) |
| BME280 | I2C / SPI | 1.71V - 3.6V | VCC, GND, SCL, SDA | Yes (4.7kΩ on I2C) |
| MCP9808 | I2C | 2.7V - 5.5V | VCC, GND, SCL, SDA | Yes (4.7kΩ on I2C) |
Decision Tree: Picking the Exact Part Number
Do not waste time debating between five different I2C sensors. Use this decision matrix to lock in your bill of materials.
| Your Project Requirement | The Concrete Pick | Why This Wins |
|---|---|---|
| Need to measure sub-zero temps without negative voltage math headaches. | DS18B20 | Outputs digital two's complement; no analog reference drift below 0°C. |
| Need high accuracy (±0.25°C) for a lab incubator or 3D printer thermal runaway. | MCP9808 | Factory calibrated to ±0.25°C between -40°C and +125°C; I2C is faster than 1-Wire. |
| Need temp + humidity + barometric pressure for an outdoor weather station. | BME280 | Integrates all three sensors in one 2.5x2.5mm LGA package; massive community support. |
| Just need a rough room temp reading for a basic school project under $1.50. | TMP36 | No pull-ups, no libraries, just a basic analogRead() and a voltage divider. |
Interference, Calibration, and Real-World Failure Modes
Datasheets assume perfect bench conditions. In the real world, wire length, EMI, and self-heating will ruin your data if you ignore them.
Interference Sources and Wire Length Limits
Analog sensors like the LM35 and TMP36 are highly susceptible to Electromagnetic Interference (EMI). A 3-foot unshielded wire running near an AC relay or a stepper motor driver will act as an antenna, injecting 50mV to 100mV of noise onto the signal line. Because the TMP36 scales at 10mV/°C, that noise translates directly into a 5°C to 10°C jitter in your serial plotter.
Digital sensors are immune to amplitude noise, but they suffer from capacitance limits. Standard I2C (used by the BME280 and MCP9808) is limited to roughly 30cm of wire length before bus capacitance exceeds 400pF, causing clock stretching and NACK errors. If you need to run an I2C temp sensor 5 meters away, you must use an I2C bus extender like the P82B715, or switch to a differential protocol like RS-485.
Common Failure Modes and Fixes
- DS18B20 'Parasitic Power' Fails on ESP32: The DS18B20 can draw power directly from the data line (parasitic mode), but the ESP32's GPIO pins cannot source the required 1.5mA pull-up current during the conversion phase, resulting in -127°C read errors. Fix: Always use 3-wire mode. Tie the VDD pin directly to 3.3V.
- BME280 Reads 3°C Higher Than Ambient: The BME280 contains a micro-heater for humidity sensing. If you poll the sensor at 10Hz via I2C, the IC will self-heat and report elevated temperatures. Fix: Use the 'Forced Mode' in the Bosch BME280 library, polling only once every 10 seconds, allowing the silicon to cool between reads.
- Analog Sensor Ground Loops: If your TMP36 is powered from a different 5V rail than the Arduino's ADC ground reference, ground potential differences will skew the reading. Fix: Star-ground your analog sensors. Run a dedicated ground wire from the sensor's GND pin directly to the microcontroller's GND pin, not through a shared breadboard power rail.
Do You Actually Need to Calibrate?
For analog sensors, yes. If you need precision, perform a two-point calibration using an ice-water bath (0°C) and boiling water (100°C, adjusted for your local barometric pressure) to map the actual ADC slope. For digital sensors like the MCP9808 or BME280, skip user calibration. As noted in the Adafruit MCP9808 guide, these ICs are laser-trimmed at the factory. If your digital sensor reads 2°C off, you are measuring self-heating, poor airflow, or a thermal gradient across your PCB—not a sensor that needs software offsetting.
For deeper circuit theory on how to filter the remaining analog noise using RC low-pass filters before the ADC, refer to the application notes in the Texas Instruments LM35 datasheet.






