The Sensing Principle: How the TMP36 Works
The TMP36 is a solid-state analog temperature sensor that outputs a continuous voltage directly proportional to the ambient Celsius temperature. Inside the silicon die, a bandgap reference circuit exploits the predictable temperature coefficient of a transistor's base-emitter voltage to generate a precise, linear voltage output. Unlike thermistors, which require external pull-up resistors and complex Steinhart-Hart logarithmic calculations, the TMP36 handles the linearization internally, making it the ultimate choice when you want to keep your hardware sensor simple.
Because it relies on active silicon circuitry rather than passive resistance changes, the TMP36 requires a stable DC power supply to operate. It draws roughly 50 microamps of quiescent current, meaning it generates virtually zero self-heating in still air. This low power draw and factory-calibrated linear output eliminate the need for complex external conditioning circuits, allowing microcontrollers to read physical temperature changes directly through a standard Analog-to-Digital Converter (ADC) pin.
Wiring and Pinout: Keeping the Hardware Sensor Simple
The TMP36 typically comes in a standard 3-pin TO-92 transistor package. A common beginner mistake is confusing the pinout with a standard NPN transistor like the 2N2222. To correctly identify the pins, hold the sensor so the flat face is pointing toward you and the pins are pointing down. From left to right, the pins are VCC, VOUT, and GND.
Below is the complete specification and wiring table. Note that while the sensor operates from 2.7V to 5.5V, your microcontroller's ADC reference voltage will dictate how you scale the math in software.
| Pin Number | Label | Function | Supply / Signal Range | Wiring Notes |
|---|---|---|---|---|
| 1 (Left) | +VS (VCC) | Power Supply | 2.7V to 5.5V DC | Connect to 5V on Arduino Uno, or 3.3V on ESP32. Must be clean DC. |
| 2 (Middle) | VOUT | Analog Output | 0.1V to 2.0V | Connect to an ADC pin (e.g., A0 on Uno, GPIO34 on ESP32). |
| 3 (Right) | GND | Ground Reference | 0V | Must share a common ground with the microcontroller. |
Never wire the TMP36 directly to a breadboard power rail without a decoupling capacitor. Solder or place a 0.1µF ceramic capacitor directly across the VCC and GND pins as close to the sensor body as possible. This filters out high-frequency switching noise from your microcontroller's voltage regulator.
Output Signal Math: Converting Raw ADC to Celsius
The output of the TMP36 is strictly an analog voltage. It is not a digital protocol like I2C or 1-Wire. The sensor outputs a baseline of 500mV (0.5V) at 0°C, and the voltage increases by exactly 10mV (0.01V) per degree Celsius. Therefore, no complex calibration curve is needed; you only need basic linear scaling.
Arduino Uno (5V Logic, 10-bit ADC)
The ATmega328P on the Arduino Uno features a 10-bit ADC, meaning it maps the 0-5V range to integer values between 0 and 1023. The resolution is approximately 4.88mV per step.
The Raw-to-Unit Math:
- Calculate Voltage:
Voltage = Raw_ADC × (5.0 / 1024.0) - Remove 0°C Offset:
Adjusted_V = Voltage - 0.5 - Scale to Celsius:
Temp_C = Adjusted_V × 100.0
// Arduino Uno TMP36 Reading
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
analogReference(DEFAULT); // 5V reference
}
void loop() {
int raw_adc = analogRead(sensorPin);
float voltage = raw_adc * (5.0 / 1024.0);
float tempC = (voltage - 0.5) * 100.0;
float tempF = (tempC * 9.0 / 5.0) + 32.0;
Serial.print("Temp: "); Serial.print(tempC); Serial.println(" C");
delay(1000);
}
ESP32-WROOM-32 (3.3V Logic, 12-bit ADC)
Interfacing with an ESP32 requires more care. The ESP32's ADC is notoriously non-linear at the extremes of its 0-3.3V range. Fortunately, the TMP36's output (0.5V to 1.5V for 0°C to 100°C) sits perfectly in the ESP32's linear mid-range. Furthermore, modern ESP32 Arduino Core versions (v2.0.0 and newer) include the analogReadMilliVolts() function, which automatically applies the factory-stored eFuse Vref calibration data to correct ADC non-linearities.
// ESP32 TMP36 Reading (Arduino Core v2.x/v3.x)
const int sensorPin = 34; // GPIO34 is ADC1_CH6, input only
void setup() {
Serial.begin(115200);
// Optional: Set attenuation if using older core, but analogReadMilliVolts handles it
analogSetPinAttenuation(sensorPin, ADC_11db);
}
void loop() {
// analogReadMilliVolts returns calibrated millivolts directly
uint32_t millivolts = analogReadMilliVolts(sensorPin);
float voltage = millivolts / 1000.0;
// TMP36 Math: 500mV offset, 10mV per degree C
float tempC = (voltage - 0.5) * 100.0;
Serial.printf("Calibrated V: %.3f | Temp: %.2f C\n", voltage, tempC);
delay(1000);
}
Common Interference Sources and Calibration
While the TMP36 is factory-calibrated to ±1°C accuracy at 25°C, real-world environments introduce interference that can ruin your readings if ignored. Understanding these sources is critical when deploying analog sensors in permanent installations.
1. Electromagnetic Interference (EMI) and Mains Hum
Analog voltage signals are highly susceptible to capacitive coupling from nearby AC mains wiring or switching power supplies. If your sensor wires run parallel to 120V/240V AC lines, the 50Hz/60Hz magnetic field will induce a ripple on the VOUT line. Fix: Use twisted-pair wire for the VOUT and GND connections, and keep analog signal cables at least 6 inches away from AC conduits.
2. Voltage Drop on Long Wire Runs
The TMP36 output is ratiometric to its supply voltage. If you power the sensor with 5V over 10 meters of thin 24 AWG wire, the voltage at the sensor's VCC pin might drop to 4.6V due to wire resistance. While the TMP36's internal bandgap reference compensates for supply variations to some degree, severe sags will shift the output baseline. Fix: For runs longer than 3 meters, use thicker wire (20 AWG or lower) or place a local 3.3V LDO regulator at the sensor end.
3. Digital Noise from Microcontrollers
When an ESP32 transmits data over WiFi, it draws current spikes exceeding 300mA. If the TMP36 shares the same breadboard power rail without local decoupling, these current spikes cause micro-brownouts on the VCC rail, manifesting as sudden 2°C to 3°C spikes in your temperature data. Fix: The 0.1µF ceramic capacitor mentioned earlier is non-negotiable. For severe WiFi noise, add a 10µF electrolytic capacitor in parallel.
Frequently Asked Questions (FAQ)
How to keep an Arduino sensor simple for beginners?
The easiest way to keep your first sensor simple is to avoid digital protocols like I2C or SPI until you understand basic circuit concepts. The TMP36 requires only three wires and no external libraries. By focusing on reading a raw analog voltage and applying basic algebra (the 10mV/°C scale factor), beginners learn the foundational relationship between physical phenomena and ADC resolution without getting bogged down in register maps or bus addresses.
Is an analog sensor simple to wire for 3.3V logic boards?
Yes, but you must respect the voltage limits. The TMP36 operates perfectly on a 3.3V supply, which is ideal for ESP32, Raspberry Pi Pico, and STM32 boards. However, you must ensure that the sensor's VCC pin never exceeds 5.5V, and the output voltage never exceeds your microcontroller's ADC maximum (usually 3.3V). Because the TMP36 maxes out around 2.0V at 150°C, it is inherently safe for 3.3V ADC pins when powered by a 3.3V source.
Why is my simple sensor output drifting over time?
If your readings slowly drift upward by 1°C to 2°C over several minutes, you are likely experiencing thermal mass and self-heating or airflow starvation. While the TMP36 draws very little current, if it is potted in epoxy, encased in heat-shrink tubing, or placed inside a sealed plastic enclosure with a warm microcontroller, the heat has nowhere to dissipate. Ensure the sensor is exposed to ambient airflow and kept physically separated from heat-generating components like voltage regulators or motor drivers.
Can I use the TMP36 to measure liquid temperatures?
The bare TO-92 package is not waterproof and will short out or corrode if submerged. To measure liquids while keeping the sensor simple, you must waterproof the assembly. Slip the sensor into a small piece of heat-shrink tubing, seal the bottom with a dab of marine-grade epoxy or hot glue, and ensure the wire connections are completely encapsulated. Be aware that adding waterproofing layers increases the thermal mass, meaning the sensor will take longer to react to rapid temperature changes in the liquid.






