The Core Question: How Does a Sensor Work?
At its core, a sensor is a transducer. It converts a physical phenomenon (like heat, light, or pressure) into a measurable electrical signal. In the case of the Analog Devices TMP36—a ubiquitous, low-cost ($1.50–$3.00) TO-92 temperature sensor—the physical property is ambient temperature, and the electrical output is a continuous analog voltage. Inside the silicon die, a bandgap reference circuit exploits the predictable temperature-dependent voltage drop across a semiconductor junction to generate a signal that scales linearly with Celsius degrees.
Unlike digital sensors that output discrete 1s and 0s over an I2C or SPI bus, an analog sensor works by varying its output pin's voltage in direct proportion to the measured environment. The microcontroller doesn't read the temperature directly; it reads the voltage using an Analog-to-Digital Converter (ADC) and relies on you to do the math to translate that voltage back into a physical unit.
Wiring the TMP36: Pinout and Power Requirements
Before writing code, you must provide a clean power rail. The TMP36 is highly sensitive to power supply noise, which directly translates to temperature reading jitter. Below is the standard pinout for the TO-92 package (flat side facing you, pins pointing down).
| Pin Number | Name | Function | Supply / Signal Range |
|---|---|---|---|
| 1 | VCC | Power Supply | 2.7V to 5.5V DC |
| 2 | VOUT | Analog Output | 0.1V to 2.0V (Typical) |
| 3 | GND | Ground | 0V (System Common) |
The Math: Converting Raw ADC Readings to Celsius
The output of the TMP36 is strictly an analog voltage. It is not a resistance, and it is not a digital bitstream. The sensor outputs 10mV per °C, with a 500mV DC offset. This offset is critical: it allows the sensor to read negative temperatures (down to -40°C, which outputs 0.1V) without requiring a negative supply rail.
To get a physical temperature reading, your microcontroller's ADC must sample this voltage. Here is the exact raw-to-unit math for a standard 5V Arduino Uno (10-bit ADC, 1024 steps):
- ADC to Voltage:
voltage = (adc_raw * 5.0) / 1024.0; - Voltage to Celsius:
temp_c = (voltage - 0.5) * 100.0; - Celsius to Fahrenheit (Optional):
temp_f = (temp_c * 9.0 / 5.0) + 32.0;
Here is a complete, copy-pasteable Arduino sketch that implements this math with a 20-sample rolling average to smooth out ADC jitter:
// TMP36 Smoothing Code for 5V Arduino Uno
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
long rawSum = 0;
for(int i = 0; i < 20; i++) {
rawSum += analogRead(sensorPin);
delay(2);
}
float adcAvg = rawSum / 20.0;
float voltage = (adcAvg * 5.0) / 1024.0;
float tempC = (voltage - 0.5) * 100.0;
Serial.println(tempC);
delay(500);
}
Note for ESP32 users: The ESP32 features a 12-bit ADC (4096 steps) but operates on a 3.3V logic rail. Furthermore, the ESP32's internal ADC is notoriously non-linear at the extreme high and low voltage ends. If you are using an ESP32, restrict your TMP36 readings to the 0.5V–2.5V range, or use an external ADC like the ADS1115 for precision work.
Real-World Interference and Calibration
In a lab, the math above is perfect. On a messy workbench, your readings will fluctuate by 2–3 degrees. Here are the most common interference sources and how to fix them:
- ADC Reference Drift: If you power the TMP36 from the Arduino's 5V pin, and that 5V pin sags to 4.8V when a servo motor turns on, your temperature reading will artificially spike. Fix: Use the microcontroller's internal voltage reference (e.g.,
analogReference(INTERNAL)on AVR boards) or power the sensor from a dedicated low-dropout (LDO) regulator. For deeper technical specifications on reference voltages, refer to the Arduino analogReference() documentation. - Electromagnetic Interference (EMI): Long, unshielded jumper wires act as antennas, picking up 50/60Hz mains hum and high-frequency switching noise from nearby buck converters. Fix: Keep analog signal wires under 12 inches, route them away from AC mains, and add a 10kΩ resistor in series with the VOUT pin, followed by a 0.1µF capacitor to ground at the microcontroller pin to form a low-pass RC filter.
- Thermal Mass and Self-Heating: The TMP36 draws about 50µA, but if breadboard contacts are loose, localized resistance can cause minor self-heating. Fix: Solder the sensor to a PCB for stable thermal coupling.
Calibration Protocol: The TMP36 is factory-calibrated, but for high-accuracy applications, perform a single-point offset calibration. Submerge the sensor (sealed in a waterproof epoxy or heat-shrink tube) in a stirred ice-water bath. It should read exactly 0°C (0.5V). If it reads 0.8°C, subtract 0.8 from all subsequent software calculations. Note that the TMP36 is part of a family; the TMP35 outputs 10mV/°C but has no offset (0°C = 0V), making it useless for sub-zero environments. Always verify the exact part number printed on the flat face of the TO-92 package; confusing a TMP35 for a TMP36 will result in readings that are exactly 50°C off. Full electrical characteristics can be found in the Analog Devices TMP36 Datasheet.
Frequently Asked Questions
How does a digital sensor work compared to an analog one?
A digital sensor (like the BME280 or DS18B20) contains an internal ADC and a communication controller. It performs the raw-to-unit math on its own silicon and transmits the final physical value as discrete digital packets over I2C, SPI, or 1-Wire. An analog sensor, as detailed above, outputs a raw, continuous voltage that requires the host microcontroller to handle the ADC conversion and scaling math. Digital sensors are immune to voltage drops over long wires, whereas analog sensors suffer from signal degradation over distance.
How does a sensor work when the microcontroller supply voltage fluctuates?
The TMP36 is a ratiometric sensor. This means its output voltage scales proportionally with its supply voltage. If you power the TMP36 from the same 5V rail that acts as your Arduino's ADC reference, a 5% drop in the 5V rail drops both the sensor's output and the ADC's reference by 5%, effectively canceling out the error. However, if you power the sensor from a separate 3.3V LDO but use the Arduino's 5V USB rail as the ADC reference, supply fluctuations will introduce massive reading errors. Always ensure the sensor's VCC and the ADC's voltage reference share the same source.
How does a sensor work reliably over long cable runs?
Analog voltage signals degrade over long cable runs due to wire resistance and capacitive coupling of environmental noise. To make an analog sensor work over distances greater than 3 feet, you must convert the voltage signal to a 4-20mA current loop using a transmitter IC (like the XTR115). Current loops are immune to voltage drops across long wire resistance. If adding a current loop is too complex for your project, abandon the analog sensor and switch to a digital sensor (like a 1-Wire DS18B20), which can reliably transmit data over 100 meters of standard Cat5 cable.






