When builders ask what does a temp sensor do in an embedded circuit, the short answer is that it acts as an analog front-end, transducing thermal energy into a proportional electrical signal that a microcontroller can quantify. But moving from a generic concept to a working prototype requires understanding the exact output type, the raw-to-unit math, and the physical limitations of the silicon. This guide cuts through the abstraction to give you the exact wiring, transfer functions, and a concrete decision matrix for your next Arduino, ESP32, or Raspberry Pi build.

The Core Function: What Does a Temp Sensor Do at the Silicon Level?

At the semiconductor level, a temperature sensor exploits the predictable temperature coefficient of a physical material. In modern silicon bandgap sensors (like the TMP36 or MCP9808), the device measures the difference in base-emitter voltage ($V_{BE}$) between two bipolar transistors operated at different current densities. Because this voltage delta is strictly proportional to absolute temperature (PTAT), the silicon can map thermal energy to an electrical voltage with high linearity.

For your microcontroller, the sensor serves as the physical interface to the environment. It takes the chaotic kinetic energy of heat and packages it into either a continuous DC voltage (analog) or a serialized binary word (digital). The microcontroller's job is strictly to sample that electrical state via an ADC or I2C bus, and apply a mathematical transfer function to map it back to degrees Celsius.

Analog vs. Digital Outputs: What You Actually Read on the Pins

A common point of failure in DIY builds is conflating analog and digital outputs. You must know exactly what the sensor is pushing onto the wire.

Rule of Thumb: An analog sensor outputs a physical voltage level that changes continuously. A digital sensor outputs a protocol packet (I2C, SPI, 1-Wire) containing a pre-calculated binary number. Never wire an analog sensor directly to an I2C bus, and never feed a digital sensor's data pin into an ADC.
  • Analog Output (e.g., TMP36, LM35): The output pin sources a continuous DC voltage (typically 10mV per °C). Your MCU must use its internal Analog-to-Digital Converter (ADC) to sample this voltage. The resolution is limited by your MCU's ADC bit-depth and reference voltage stability.
  • Digital Output (e.g., MCP9808, DS18B20, BME280): The sensor contains its own internal ADC and logic gates. It digitizes the temperature internally and transmits it as a 16-bit register value over a digital bus. The MCU reads raw hex bytes, completely bypassing the MCU's noisy internal ADC.

Wiring and Pinout Reference

Below is the hardware specification and wiring table for the two most common baseline sensors used in ESP32 and Arduino projects. Always verify the supply range; pushing 5V into a 3.3V I2C sensor will permanently destroy the silicon.

Specification TMP36 (Analog Silicon) MCP9808 (Digital I2C)
Supply Range (VDD) 2.7V to 5.5V 2.7V to 5.5V
Output Type Analog Voltage (10mV/°C) Digital I2C (16-bit register)
Interface Pins VDD, GND, VOUT VDD, GND, SCL, SDA
Default I2C Address N/A 0x18 (configurable via A0-A2)
Accuracy (Typical) ±1°C to ±2°C ±0.25°C

The Math: Converting Raw ADC and Register Data to Celsius

Reading the pin is only 10% of the work. The real engineering happens in the transfer function. Here is the exact raw-to-unit math for both paradigms.

Analog Math: TMP36 on a 10-bit ADC (3.3V Reference)

The TMP36 outputs 0.5V at 0°C, and scales by 10mV (0.01V) per degree. If you are using a standard Arduino Uno (5V, 10-bit) or an ESP32 (3.3V, 12-bit), you must scale the raw ADC integer back to a voltage, then apply the sensor's offset. Note that the ESP32's internal ADC is notoriously non-linear at the extreme high and low voltage rails; keep your sensor's output voltage between 0.15V and 2.8V for best results.

// ESP32 12-bit ADC (0-4095) at 3.3V reference
const float adcResolution = 3.3 / 4096.0;
float voltage = rawAdcReading * adcResolution;
// TMP36 has a 500mV (0.5V) offset at 0°C
float tempC = (voltage - 0.5) * 100.0; 

Digital Math: MCP9808 I2C Register Parsing

The MCP9808 stores temperature in a 16-bit Ambient Temperature Register (0x05). The upper 3 bits are alert flags, and the lower 13 bits contain the signed temperature data in two's complement format. You cannot just read the integer; you must mask the flags and handle the sign bit.

uint16_t raw = Wire.read() << 8; // Read MSB
raw |= Wire.read();              // Read LSB

// Clear the upper 3 flag bits (bits 15, 14, 13)
raw &= 0x1FFF; 

float tempC = raw / 16.0;

// Handle negative temperatures (Sign bit is bit 12)
if (raw & 0x1000) {
  tempC -= 256.0;
}

Interference, Self-Heating, and Calibration Gotchas

Sensors do not exist in a vacuum. When your readings drift or spike, it is almost always due to one of three physical interference sources.

  • Electromagnetic Interference (EMI) on Analog Lines: Analog sensors like the TMP36 have high-impedance output stages. A 2-inch wire run on a breadboard next to a switching buck converter or an ESP32 WiFi antenna will act as an antenna, injecting high-frequency noise into your ADC. Fix: Place a 0.1µF ceramic bypass capacitor directly across the VDD and GND pins of the sensor, and keep analog traces under 6 inches.
  • Ground Loops in Long Runs: If you share a long ground wire between a high-current load (like a motor or LED strip) and an analog temperature sensor, the voltage drop across the ground wire will artificially offset your ADC reading. Fix: Use differential signaling, or switch to a digital I2C/1-Wire sensor which is immune to ground-reference shifts.
  • Self-Heating: Every sensor consumes quiescent current ($I_q$), which dissipates as heat inside the plastic package ($I^2R$). While a digital MCP9808 draws only ~200µA (negligible heating), driving a 10kΩ NTC thermistor with a high excitation current can artificially raise the die temperature by 1°C to 2°C. Fix: Use high-value pull-up resistors (100kΩ+) for thermistor voltage dividers, or switch to low-power digital silicon sensors.
  • Calibration and Scaling: Silicon bandgap sensors (TMP36, MCP9808) are laser-trimmed at the factory and require zero user calibration for general hobbyist use. If you are using raw NTC thermistors, you must implement the Steinhart-Hart equation and perform a 3-point ice/boiling/room calibration to extract the A, B, and C coefficients. For 95% of embedded projects, skip the thermistor and use factory-trimmed silicon.

Decision Tree: Which Sensor to Buy for Your Next Build

Stop guessing in the parts aisle. Use this decision matrix to select the exact component for your environmental constraints.

Application Constraint Recommended Sensor Type Concrete Part Number
Long wire runs (>3 meters) or wet environments 1-Wire Digital (Parasitic Power capable) Dallas DS18B20 (Waterproof probe variant)
High precision (±0.25°C) on a standard I2C bus Silicon I2C Digital Microchip MCP9808 (Adafruit Product ID 1782)
Ultra-low cost, short wires, basic overheat protection Analog Silicon Analog Devices TMP36
Need Temp + Humidity + Pressure simultaneously Multi-sensor I2C/SPI Bosch BME280 (Avoid the DHT11/DHT22 for new designs)
The Default Recommendation: If your project does not involve submerging the sensor in water or running wires across a room, buy the MCP9808 I2C breakout. It eliminates ADC noise, requires only 4 wires, provides ±0.25°C accuracy out of the box, and has extensive library support across Arduino and CircuitPython. It is the definitive default for modern microcontroller ambient sensing.

For further reading on silicon sensor architectures, refer to the Analog Devices TMP36 datasheet for analog transfer curves, and the Adafruit MCP9808 learning guide for I2C register mapping and Python implementation details.