How Do Temperature Sensors Work in Embedded Systems?

Temperature sensors in embedded systems work by measuring a temperature-dependent physical property—most commonly the forward voltage drop of a silicon PN junction (bandgap sensors) or the resistance change in a ceramic/metal oxide (thermistors). When you ask how do temperature sensors work in the context of an ESP32 or Raspberry Pi, the answer splits into two distinct hardware realities: internal silicon monitoring and external ambient measurement.

Internal MCU sensors (like the one built into the ESP32) rely on a silicon bandgap reference. As the silicon die heats up, the forward voltage of a dedicated sensing transistor drops at a predictable rate (roughly -2mV/°C). The onboard ADC digitizes this drop to report die temperature. However, this sensor measures the silicon junction, not your PCB ambient. During a WiFi transmit burst, the ESP32 die can spike 15°C to 20°C above the surrounding FR4 fiberglass.

For true thermal management, you need external sensors. Digital I2C sensors like the Texas Instruments TMP117 use a precision bandgap circuit calibrated to ±0.1°C accuracy. NTC thermistors (like the ubiquitous 10kΩ B3950) work via the Steinhart-Hart equation, where resistance drops exponentially as heat increases thermal electron mobility in the metal oxide. If you are calculating thermal margins for a power supply, you must place an external sensor near the component case to measure true local ambient ($T_A$), rather than trusting the MCU's internal die reading.

Bench Rule: Never use the ESP32's internal temperature sensor to calculate heatsink requirements for an external voltage regulator. The internal sensor tracks MCU RF/compute load, while the external regulator tracks peripheral load. They are thermally decoupled.

Translating Sensor Data: Thermal Path Math and Rθ Values

Once your external TMP117 or thermistor gives you a reliable ambient temperature ($T_A$) reading, you need to calculate if your power components are silently cooking themselves. This requires thermal resistance math, denoted as $R_{\theta}$ (R-theta), measured in °C/W. Think of $R_{\theta}$ exactly like electrical resistance, but for heat flow: temperature is voltage, power dissipation is current, and thermal resistance is ohms.

The fundamental thermal path equation is:

$T_J = T_A + (P_D \times R_{\theta JA})$

  • $T_J$: Junction temperature (the actual silicon inside the package).
  • $T_A$: Ambient temperature (measured by your sensor).
  • $P_D$: Power dissipated in watts.
  • $R_{\theta JA}$: Junction-to-Ambient thermal resistance.

Let us look at a real-world failure scenario. You are powering a Raspberry Pi Zero and a 5V relay board (combined 1A draw) from a 12V solar battery using an LM317T linear regulator in a TO-220 package.

ParameterValueNotes
Input Voltage ($V_{in}$)12.0VNominal solar battery
Output Voltage ($V_{out}$)5.0VPi Zero requirement
Load Current ($I$)1.0APeak compute + relay coil
Power Dissipation ($P_D$)7.0W$(12V - 5V) \times 1.0A$
$R_{\theta JC}$ (Junction-to-Case)3.0°C/WTO-220 package spec
$R_{\theta CS}$ (Case-to-Sink)0.5°C/WUsing thermal compound

If you rely on the bare TO-220 tab without a heatsink, the $R_{\theta JA}$ is roughly 50°C/W. If your enclosure sensor reads $T_A = 30°C$, the math yields: $T_J = 30 + (7 \times 50) = 380°C$. The silicon will literally melt and desolder itself long before hitting this number, but the internal thermal shutdown will trip at 150°C, causing the Pi to brownout and corrupt the SD card.

Derating Curves and "How Hot is Too Hot?"

How hot is too hot for this part? The absolute maximum junction temperature for most commercial silicon is 125°C or 150°C. However, designing to the absolute max is a rookie mistake. Reliability drops exponentially above 85°C due to accelerated electromigration and dielectric breakdown.

This is where derating curves come in. If you read the TI thermal design guidelines for linear regulators, you will see that a TO-220 package might be rated for 15W at 25°C ambient, but it must be derated linearly to 0W at 150°C. The slope of this line dictates your true power limit. For the LM317, the derating factor is roughly 120 mW/°C above 25°C. If your enclosure sensor reads a 60°C ambient, your maximum allowed power dissipation drops from 15W to roughly 10.8W.

Failure Signatures of Thermal Stress: Do not wait for thermal shutdown to tell you your design is failing. Look for these early signatures:
1. I2C/SPI Bus Lockups: Electromigration in the MCU's GPIO transistors increases leakage current, causing logic threshold drift and phantom interrupts.
2. Watchdog Resets: The MCU's internal RC oscillator drifts out of spec at high temperatures, causing timing faults.
3. Solder Joint Fatigue: Repeated thermal cycling (heating up under load, cooling down at idle) causes micro-cracks in BGA or leadframe solder joints due to CTE (Coefficient of Thermal Expansion) mismatch between the silicon, copper, and FR4.

Heatsink Selection and Airflow: What Actually Buys You Margin?

Let us fix the 7W LM317 problem. Our target is to keep $T_J$ under 100°C for long-term reliability. Our sensor reads a worst-case enclosure ambient ($T_A$) of 40°C.

Maximum allowed total thermal resistance: $R_{\theta JA(max)} = (100°C - 40°C) / 7W = 8.57°C/W$.
We know $R_{\theta total} = R_{\theta JC} + R_{\theta CS} + R_{\theta SA}$ (Sink-to-Ambient).
$8.57 = 3.0 + 0.5 + R_{\theta SA}$.
Required $R_{\theta SA} = 5.07°C/W$.

A bare TO-220 tab is 50°C/W. We need a physical heatsink. The Aavid (Boyd) 532602B02500G is a standard extruded aluminum TO-220 heatsink. In natural convection (still air inside an enclosure), its $R_{\theta SA}$ is rated at roughly 12°C/W. This is insufficient; $12 + 3.5 = 15.5°C/W$, which puts $T_J$ at 148°C.

What airflow and enclosure changes buy you:
Adding forced convection drastically alters the boundary layer of stagnant air around the fins. If you mount a 30mm 5V Sunon MagLev fan blowing 10 CFM across the Aavid 532602B02500G, the effective $R_{\theta SA}$ drops from 12°C/W to approximately 4.5°C/W.
New $T_J = 40 + 7 \times (3.0 + 0.5 + 4.5) = 96°C$. You have successfully bought your thermal margin.

Alternatively, if you cannot add a fan, you must change the topology. Swapping the LM317 linear regulator for a RECOM R-78E5.0-1.0 switching buck converter drops the power dissipation from 7W to roughly 0.6W (at 90% efficiency). At 0.6W, the bare TO-220 tab without any heatsink yields a $T_J$ of just 70°C. Espressif's hardware design guidelines heavily favor switching topologies for this exact thermal reason when powering RF-heavy embedded boards.

The Thermal Management Decision Tree

Stop guessing heatsink sizes. Use this decision matrix based on your sensor data and power calculations to terminate on a concrete hardware choice.

Condition (Based on Math)Action / TopologyConcrete Part Pick
$V_{in} - V_{out} < 1V$ and $I < 300mA$ Use an LDO. No heatsink required. Ensure adequate PCB copper pour for $R_{\theta JA}$. TI TPS7A47 (Ultra-low noise, low dropout)
$V_{in} - V_{out} > 2V$ and $P_D < 1.5W$ Use an LDO with a PCB-mount extruded heatsink or large thermal vias to an internal ground plane. TI LM317 + Aavid 577202B00000G (SOT-223/TO-220 board mount)
$V_{in} - V_{out} > 2V$ and $P_D > 1.5W$ Abandon linear regulation. Switch to a DC-DC buck converter. Heatsink likely unnecessary. RECOM R-78E series (Pin-compatible TO-220 drop-in switching replacement)
Driving high-current loads (Motors/LEDs) via MOSFET Calculate $I^2R_{DS(on)}$. If $P_D > 0.5W$, add a heatsink or parallel two FETs to halve $R_{DS(on)}$. IRLZ44N (Logic level) + thermal pad to chassis
Enclosure $T_A$ exceeds 50°C Add forced convection (fan) or relocate heat-generating components outside the sealed IP enclosure. Sunon MF35101VX (30mm 5V MagLev fan)

Thermal management is not a mystery; it is a strict accounting of watts and degrees. Measure your true ambient with a dedicated external sensor, run the $R_{\theta}$ math, and let the derating curves dictate your physical hardware. When the math demands a 5°C/W sink and your enclosure has no airflow, you do not negotiate with the silicon—you change the power topology.