The LM35 gives a voltage proportional to temperature — 10 mV per degree Celsius — with no calibration and no library. It needs 5 V, which the Pico has on VBUS when it runs from USB, but its output stays far below 3.3 V, so it goes straight into GP26 (ADC0).
The script averages 64 readings for a steady value and prints it next to the RP2040’s built-in temperature sensor.
Wiring
| Raspberry Pi Pico | LM35 temperature sensor (TO-92) | Wire | Notes |
|---|---|---|---|
| VBUS | +VS | red | VBUS (pin 40), 5 V. The LM35 needs at least 4 V — 3V3 is not enough. |
| GP26 | VOUT | green | GP26 = ADC0, physical pin 31. VOUT is 0.25 V at 25 °C and 1.5 V at 150 °C — no divider needed. |
| AGND | GND | black | AGND (pin 33) is the analog ground beside the ADC pins. |
4–30 V (use 5 V) part, 3.3 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
- This is the one 5 V-powered sensor you can wire straight to a Pico ADC pin: its output is only 10 mV per °C, far below 3.3 V.
- One ADC step is about 0.8 mV, i.e. 0.08 °C, but the RP2040 ADC is noisy — the script averages 64 readings. Using AGND rather than a digital GND helps too.
- Hold it by the flat face towards you, legs down: +VS, VOUT, GND from left to right. Wired backwards it gets hot within seconds.
- The script also prints the RP2040’s own temperature sensor (
ADC(4)) — expect it a few degrees higher, since it measures the chip.
Code
# LM35 analog temperature sensor on a Raspberry Pi Pico (MicroPython).
# Wiring: +VS -> VBUS (pin 40, 5 V - the LM35 needs at least 4 V), VOUT -> GP26 / ADC0 (pin 31),
# GND -> AGND (pin 33). VOUT is only 10 mV per C (0.25 V at 25 C), so it is safe for the ADC.
from machine import ADC, Pin
import time
lm35 = ADC(26)
chip = ADC(4) # RP2040 internal sensor, for comparison
led = Pin(25, Pin.OUT)
def lm35_c(n=64):
raw = sum(lm35.read_u16() for _ in range(n)) / n # heavy averaging: each ADC step is ~0.08 C
return raw * 3.3 / 65535 * 100 # 10 mV per C
def chip_c():
return 27 - (chip.read_u16() * 3.3 / 65535 - 0.706) / 0.001721
print("LM35 on GP26")
while True:
t = lm35_c()
led.value(t > 40) # LED on above 40 C
print("LM35 {:.1f} C (RP2040 chip {:.1f} C)".format(t, chip_c()))
time.sleep(1)# LM35 analog temperature sensor on a Raspberry Pi Pico (MicroPython).
# Wiring: +VS -> VBUS (pin 40, 5 V - the LM35 needs at least 4 V), VOUT -> GP26 / ADC0 (pin 31),
# GND -> AGND (pin 33). VOUT is only 10 mV per C (0.25 V at 25 C), so it is safe for the ADC.
from machine import ADC, Pin
import time
lm35 = ADC(26)
chip = ADC(4) # RP2040 internal sensor, for comparison
led = Pin(25, Pin.OUT)
def lm35_c(n=64):
raw = sum(lm35.read_u16() for _ in range(n)) / n # heavy averaging: each ADC step is ~0.08 C
return raw * 3.3 / 65535 * 100 # 10 mV per C
def chip_c():
return 27 - (chip.read_u16() * 3.3 / 65535 - 0.706) / 0.001721
print("LM35 on GP26")
while True:
t = lm35_c()
led.value(t > 40) # LED on above 40 C
print("LM35 {:.1f} C (RP2040 chip {:.1f} C)".format(t, chip_c()))
time.sleep(1)Expected serial output
LM35 on GP26
LM35 28.4 C (RP2040 chip 31.2 C)
LM35 28.5 C (RP2040 chip 31.2 C)LM35 on GP26 LM35 28.4 C (RP2040 chip 31.2 C) LM35 28.5 C (RP2040 chip 31.2 C)
Common errors
Reads a few degrees too high or too low
The RP2040 ADC has an offset error at low voltages. Compare with a known thermometer once and add a fixed correction in code.
Sensor gets hot, reading nonsense
It is in back to front. Unplug it at once and check the pin order (flat face towards you: +VS, VOUT, GND).