The LM35 is a three-legged analog temperature sensor whose output is simply 10 mV per °C: 285 mV means 28.5 °C. There is no library and no protocol, which makes it a classic first analog sensor in Indian college labs.
On the Uno there is one trick that matters. The ADC divides its reference voltage into 1024 steps. With the default 5 V reference, each step is 4.9 mV — about half a degree, so the reading jumps in 0.5 °C steps. The ATmega328P has an internal 1.1 V reference. Switch to it, and each step becomes about 1 mV, or 0.1 °C, while still covering 0–110 °C.
The sketch switches the reference, throws away the first few readings while it settles, and averages 32 readings for a steady result.
Wiring
| Arduino Uno R3 | LM35 temperature sensor (TO-92) | Wire | Notes |
|---|---|---|---|
| 5V | +VS | red | Left leg, flat face towards you. |
| A0 | VOUT | yellow | Middle leg. 10 mV per °C. |
| GND | GND | black | Right leg. Reversing +VS and GND makes the LM35 hot within seconds. |
4–30 V (use 5 V) part, 5 V board. The LM35 needs at least 4 V, so power it from 5 V even on ESP32 and Pico. That’s safe: VOUT is only 10 mV/°C (1.5 V at 150 °C), well inside a 3.3 V ADC. Never feed it from 3.3 V.
Board quirks
- With the default 5 V reference one ADC step is 4.9 mV, or about 0.5 °C.
analogReference(INTERNAL)switches the Uno to its 1.1 V reference: about 1.07 mV, or 0.1 °C per step, up to 110 °C. - The internal reference is only 1.0–1.2 V from chip to chip. Measure the AREF pin with a multimeter while the sketch runs and put the value in
VREF_MV. - With the internal reference active, never connect anything to AREF, and remember it applies to every analog pin — a 5 V sensor on A1 will now read 1023.
- The basic LM35 (LM35DZ) only reads 0 °C and above on a single supply. Fakes are common: if it reads 10 °C off, try another one before blaming the code.
- On a long cable the LM35 can oscillate. A 75 Ω resistor in series with VOUT and a 1 µF capacitor to GND at the Uno end stops it.
Code
// LM35 temperature sensor on an Arduino Uno R3.
// +VS → 5V, VOUT → A0, GND → GND (flat face towards you: +VS, VOUT, GND from left).
// Uses the Uno's internal 1.1 V reference: 1.1 V / 1024 = about 1.07 mV per step,
// so each step is about 0.1 °C instead of 0.5 °C with the 5 V reference.
const uint8_t LM35_PIN = A0;
const float VREF_MV = 1100.0; // measure your Uno's AREF pin with a meter and put the value here
void setup() {
analogReference(INTERNAL); // 1.1 V full scale = up to 110 °C
Serial.begin(9600);
for (uint8_t i = 0; i < 5; i++) analogRead(LM35_PIN); // first readings after a reference change are off
Serial.println(F("LM35 on A0, 1.1 V reference"));
}
void loop() {
long sum = 0;
for (uint8_t i = 0; i < 32; i++) sum += analogRead(LM35_PIN);
float mv = (sum / 32.0) * VREF_MV / 1024.0;
float c = mv / 10.0; // 10 mV per °C
Serial.print(F("VOUT "));
Serial.print(mv, 1);
Serial.print(F(" mV Temp "));
Serial.print(c, 1);
Serial.println(F(" C"));
delay(1000);
}// LM35 temperature sensor on an Arduino Uno R3.
// +VS → 5V, VOUT → A0, GND → GND (flat face towards you: +VS, VOUT, GND from left).
// Uses the Uno's internal 1.1 V reference: 1.1 V / 1024 = about 1.07 mV per step,
// so each step is about 0.1 °C instead of 0.5 °C with the 5 V reference.
const uint8_t LM35_PIN = A0;
const float VREF_MV = 1100.0; // measure your Uno's AREF pin with a meter and put the value here
void setup() {
analogReference(INTERNAL); // 1.1 V full scale = up to 110 °C
Serial.begin(9600);
for (uint8_t i = 0; i < 5; i++) analogRead(LM35_PIN); // first readings after a reference change are off
Serial.println(F("LM35 on A0, 1.1 V reference"));
}
void loop() {
long sum = 0;
for (uint8_t i = 0; i < 32; i++) sum += analogRead(LM35_PIN);
float mv = (sum / 32.0) * VREF_MV / 1024.0;
float c = mv / 10.0; // 10 mV per °C
Serial.print(F("VOUT "));
Serial.print(mv, 1);
Serial.print(F(" mV Temp "));
Serial.print(c, 1);
Serial.println(F(" C"));
delay(1000);
}Expected serial output
LM35 on A0, 1.1 V reference
VOUT 284.6 mV Temp 28.5 C
VOUT 285.1 mV Temp 28.5 CLM35 on A0, 1.1 V reference VOUT 284.6 mV Temp 28.5 C VOUT 285.1 mV Temp 28.5 C
Common errors
Reads about 5× too high or always near 110 °C
The math assumes 1.1 V but the reference is still 5 V (or the other way round). Keep analogReference(INTERNAL) and VREF_MV = 1100 together.
The sensor is too hot to touch
Wired backwards. Unplug at once. With the flat face towards you: +VS, VOUT, GND from left.
Value jumps by a degree
Noise on the wire. Keep the averaging, add 100 nF from VOUT to GND, and keep the wire away from motor and relay wiring.