Temperature sensors work by converting thermal energy into a measurable electrical signal—either a varying voltage (analog) or a serial data stream (digital). For analog ICs like the TMP36, temperature changes alter the internal semiconductor's voltage drop (typically 10mV/°C). For digital sensors like the DS18B20, an internal ADC converts this thermal shift into a binary code sent over a 1-Wire or I2C bus. Your microcontroller then reads this signal and applies a mathematical offset to output a human-readable Celsius or Fahrenheit value.
The Core Sensing Principle
Most modern integrated circuit (IC) temperature sensors rely on the temperature-dependent voltage drop across a silicon PN junction. As thermal energy increases, the bandgap voltage of the internal transistor shifts predictably at a rate of roughly -2mV/°C. Because this raw microvolt-level shift is too small and non-linear for direct microcontroller interfacing, the sensor's internal circuitry amplifies and offsets this signal, outputting a clean, macro-scale voltage or digital word that scales linearly with temperature.
Digital sensors utilize this exact same silicon bandgap principle but integrate an Analog-to-Digital Converter (ADC) and a logic controller directly onto the same silicon die. Instead of outputting a continuous raw voltage, the chip digitizes the thermal reading into discrete binary packets. It then transmits this data via protocols like I2C, SPI, or 1-Wire. This on-chip digitization completely eliminates the analog signal degradation and noise susceptibility that plagues long wire runs.
Analog vs. Digital Outputs and Wiring
The fundamental difference in interfacing comes down to what the output actually is. An analog sensor outputs a continuous voltage proportional to the temperature. You must wire this to an ADC pin on your microcontroller. A digital sensor outputs a serial data stream (high/low logic pulses) representing binary data, requiring a standard GPIO pin configured for a specific communication protocol.
| Sensor Model | Type | Output Signal | Supply Range | Interface / Pins | Avg Price (2026) |
|---|---|---|---|---|---|
| TMP36 | Analog | Voltage (10mV/°C) | 2.7V - 5.5V | 3-Pin TO-92 (VCC, OUT, GND) | ~$1.50 |
| LM35 | Analog | Voltage (10mV/°C) | 4.0V - 30V | 3-Pin TO-92 (VCC, OUT, GND) | ~$1.20 |
| DS18B20 | Digital | 1-Wire Serial | 3.0V - 5.5V | 3-Pin TO-92 (VDD, DQ, GND) | ~$2.20 |
| BME280 | Digital | I2C / SPI | 1.71V - 3.6V | 8-Pin LGA / Breakout | ~$4.50 |
Output Signal Math: Raw ADC to Celsius
Scaling a raw ADC reading into a physical unit requires knowing your microcontroller's ADC resolution and reference voltage. Here is the exact math for the ubiquitous TMP36 analog sensor.
Analog Scaling (TMP36 on 5V Arduino Uno)
The Arduino Uno features a 10-bit ADC (0-1023) with a default 5.0V reference. The TMP36 outputs 0.5V at 0°C and scales at 10mV (0.01V) per degree Celsius.
- Convert Raw to Voltage:
float voltage = (reading * 5.0) / 1023.0; - Subtract the 0°C Offset:
float offset_voltage = voltage - 0.5; - Scale to Celsius:
float tempC = offset_voltage * 100.0;
Analog Scaling (TMP36 on 3.3V ESP32)
The ESP32 features a 12-bit ADC (0-4095) and operates at 3.3V. However, you must account for the ESP32's internal voltage divider and non-linearity.
- Convert Raw to Voltage:
float voltage = (reading * 3.3) / 4095.0;(Note: This is an approximation; see gotchas below). - Scale to Celsius:
float tempC = (voltage - 0.5) * 100.0;
Digital Scaling (DS18B20)
For digital sensors, the math is handled by the silicon and the library. The DS18B20 defaults to 12-bit resolution, meaning the raw binary output is already scaled to 0.0625°C increments. If the sensor reads 0x0190 (400 in decimal), the math is simply 400 * 0.0625 = 25.0°C. The DallasTemperature library abstracts this into a simple sensors.getTempCByIndex(0) call.
Calibration, Interference, and Real-World Gotchas
Bench theory rarely survives the jobsite without adjustments. Here are the most common interference sources and calibration requirements for temperature sensors:
- ESP32 ADC Non-Linearity: The ESP32's internal ADC is notoriously non-linear, especially near the 0V and 3.3V rails. A raw reading of 100 might not perfectly scale. For precision analog readings on an ESP32, you must use the esp_adc_cal component to apply factory-stored eFuse calibration values, or simply switch to a digital I2C sensor.
- Analog EMI and Decoupling: Analog sensors are high-impedance voltage sources. If you are reading a TMP36 near a PWM motor driver or switching relay, electromagnetic interference (EMI) will induce wild voltage spikes. You must solder a 0.1µF ceramic decoupling capacitor physically adjacent to the sensor's VCC and GND pins to filter high-frequency noise.
- 1-Wire Bus Capacitance: When wiring multiple DS18B20 sensors over long distances (e.g., 30 meters of Cat5 cable), the parasitic capacitance of the wire rounds off the sharp digital edges of the 1-Wire protocol, causing CRC checksum errors. The standard 4.7kΩ pull-up resistor on the data line is too weak for long runs. Drop the pull-up resistor to 2.2kΩ or 1.5kΩ to source more current and sharpen the signal rise time.
- Self-Heating: Environmental sensors like the BME280 generate a small amount of internal heat from their I2C logic and humidity heater. If you poll the sensor continuously at 1Hz, the reading will artificially drift up by 0.5°C to 1.0°C. Configure the sensor's oversampling to 1x and use a standby time of at least 1 second between readings to allow the die to cool.
For authoritative component specifications and electrical characteristics, always refer to the manufacturer datasheets, such as the Analog Devices TMP36 Datasheet and the DS18B20 Datasheet.
Frequently Asked Questions
How do temp sensors work in extreme heat environments?
Silicon-based IC sensors (like the TMP36 or DS18B20) are fundamentally limited by the semiconductor's bandgap physics and packaging materials, typically maxing out at 125°C or 150°C. Beyond this threshold, the silicon leakage currents overwhelm the sensing junction, and the plastic TO-92 packaging begins to degrade. For extreme heat environments (e.g., kilns, exhaust manifolds, or industrial ovens up to 1200°C), you must abandon IC sensors and use a Type K thermocouple paired with a cold-junction compensation amplifier like the MAX6675 or MAX31855.
How do digital temp sensors work over long wire runs?
Digital sensors like the DS18B20 use the 1-Wire protocol, which is highly resilient over long distances because it transmits data as discrete digital packets with built-in CRC (Cyclic Redundancy Check) error detection. If noise corrupts a bit over a 50-meter cable run, the microcontroller detects the failed CRC and simply requests a retransmission, whereas an analog sensor would silently output the wrong voltage. To make digital sensors work over long runs, use twisted-pair cable, ensure a strong pull-up resistor (1.5kΩ - 2.2kΩ), and provide local VCC power rather than relying on parasitic power harvesting from the data line.
Why does my analog temp sensor output fluctuate wildly?
Wild fluctuations (e.g., jumping between 22°C and 26°C rapidly) on an analog sensor are almost always caused by a noisy ADC reference voltage or a missing decoupling capacitor. Microcontroller USB power supplies are notoriously noisy, injecting 50mV-100mV of ripple onto the 5V rail. Because the TMP36 scales at 10mV/°C, a 50mV power ripple translates directly into a 5°C fluctuation on your screen. Fix this by powering the sensor from a clean, regulated LDO voltage source, adding a 0.1µF bypass capacitor at the sensor pins, and averaging 20-50 sequential ADC reads in your firmware to smooth out transient spikes.






