The LM35 temp sensor outputs an analog voltage directly proportional to Celsius temperature at a precise scale of 10 mV/°C. Unlike digital sensors such as the DHT22 or DS18B20, the LM35 requires no pull-up resistors, I2C/SPI configuration, or digital handshaking. You simply feed it power, ground it, and read the analog pin. However, because it relies on a high-impedance analog output, interfacing it correctly with modern 3.3V microcontrollers requires specific ADC math and hardware filtering to defeat environmental noise.
Understanding the LM35 Sensing Principle and Variants
Internally, the LM35 relies on a bandgap temperature sensing circuit. It generates a voltage proportional to absolute temperature (PTAT) and subtracts a fixed internal offset to yield a 0V output at exactly 0°C. Because the output scales linearly at 10 mV per degree Celsius, you avoid the Kelvin conversion math required by raw PTAT sensors. The output is strictly an analog voltage; it does not output current (like the AD590) and possesses no digital data pin.
Texas Instruments manufactures several variants of the LM35, optimized for different temperature ranges and accuracy requirements. Selecting the wrong variant for a sub-zero application is a common bench mistake, as the standard LM35 cannot read below 2°C without a negative supply rail.
| Part Number | Temperature Range | Typical Accuracy (at 25°C) | Supply Voltage (VCC) | Packages Available |
|---|---|---|---|---|
| LM35 (Standard) | -55°C to 150°C | ±0.5°C | 4V to 30V | TO-92, TO-220, SOIC |
| LM35A (High Accuracy) | -55°C to 150°C | ±0.25°C | 4V to 30V | TO-92, TO-220, SOIC |
| LM35C (Commercial) | -40°C to 110°C | ±0.5°C | 4V to 30V | TO-92, SOIC |
| LM35D (TO-92 Only) | 0°C to 100°C | ±0.5°C | 4V to 30V | TO-92 |
Wiring the LM35 Temp Sensor to Microcontrollers
The most common package for hobbyists is the TO-92 (looking like a standard 2N2222 transistor). When looking at the flat face of the TO-92 package with the pins pointing down, the pinout from left to right is VCC, VOUT, and GND. The supply range is broad (4V to 30V), meaning you can safely power it from a 5V Arduino Uno or a 3.3V ESP32 without a level shifter.
| Pin (Flat Face View) | Function | Connection to 5V MCU (Arduino Uno) | Connection to 3.3V MCU (ESP32) |
|---|---|---|---|
| 1 (Left) | VCC (+V_S) | 5V Pin | 3V3 Pin |
| 2 (Middle) | VOUT (Signal) | Analog Pin (e.g., A0) | ADC1 Pin (e.g., GPIO34) |
| 3 (Right) | GND | GND Pin | GND Pin |
Output Signal Math: Converting ADC Raw Reads to Celsius
Because the LM35 outputs 10 mV per degree Celsius, the physical unit conversion depends entirely on your microcontroller's ADC reference voltage and bit resolution. The factory scaling is fixed; no physical calibration (like turning a trimpot) is needed for standard ±0.5°C accuracy. You only need to apply the correct software math.
Scenario A: 5V Logic (Arduino Uno / Nano / Mega)
The ATmega328P features a 10-bit ADC (1024 steps). By default, the reference voltage is 5V.
Step 1: Find the voltage per step: 5.0V / 1024 = 0.0048828V (4.88 mV) per step.
Step 2: Convert to Celsius: Since 10 mV = 1°C, divide the step voltage by 0.010.
Formula: Temperature = Raw_ADC * 0.48828
Pro-Tip for 5V Boards: The LM35 maxes out at 150°C (1.5V). Using the 5V reference wastes 70% of your ADC resolution on voltages the sensor will never reach. Use the Arduino's internal 1.1V reference instead. This changes your math to 1.1V / 1024 = 1.07mV per step, yielding a formula of Temperature = Raw_ADC * 0.107 and effectively increasing your resolution to ~0.1°C.
Scenario B: 3.3V Logic (ESP32 / ESP8266)
The ESP32 uses a 12-bit ADC (4096 steps) referenced to 3.3V.
Step 1: Voltage per step: 3.3V / 4096 = 0.0008056V (0.805 mV) per step.
Step 2: Convert to Celsius: Divide by 0.010.
Formula: Temperature = Raw_ADC * 0.08056
// Arduino Uno LM35 Code using 1.1V Internal Reference
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
// Switch to 1.1V internal reference for higher resolution
analogReference(INTERNAL);
}
void loop() {
// Read and average 10 samples to reduce noise
long rawSum = 0;
for(int i = 0; i < 10; i++) {
rawSum += analogRead(sensorPin);
delay(5);
}
float rawAvg = rawSum / 10.0;
// Math for 1.1V reference: (1.1 / 1024) / 0.010 = 0.1074
float tempC = rawAvg * 0.1074;
float tempF = (tempC * 9.0 / 5.0) + 32.0;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.print(" C | ");
Serial.print(tempF);
Serial.println(" F");
delay(1000);
}
Defeating Interference and Calibration Edge Cases
The most common complaint with the LM35 temp sensor is noisy, fluctuating readings (e.g., jumping between 23.1°C and 25.4°C randomly). This is not a sensor defect; it is an impedance and interference issue.
The Root Cause: The LM35 output stage is designed to drive very low currents (it can source up to 60 µA, but sinking current requires an external pull-down resistor). This high output impedance makes the VOUT pin act like an antenna. If you run jumper wires longer than 12 inches (30 cm) near AC mains wiring, the sensor will couple 50/60Hz electromagnetic interference directly into your microcontroller's ADC.
The Hardware Fix (RC Low-Pass Filter):
Do not rely solely on software oversampling. Add a physical RC filter at the microcontroller end of your wires. Solder a 10 kΩ series resistor on the VOUT line, followed by a 10 µF ceramic or film capacitor to ground. This creates a low-pass filter with a cutoff frequency of roughly 1.6 Hz, completely eliminating 60Hz mains hum and high-frequency switching noise from nearby breadboard power supplies.
Calibration Edge Cases:
The LM35 is laser-trimmed at the factory. If you compare it to a cheap digital multimeter temperature probe and find a 1.5°C discrepancy, trust the LM35. Multimeter thermocouples often suffer from cold-junction compensation errors. If you absolutely require lab-grade calibration, place the LM35 in a stirred ice-water bath (0°C) and a boiling water bath (adjusted for your local barometric pressure), record the ADC values, and apply a two-point linear regression map in your firmware rather than attempting to physically trim the sensor.






