Built-in project · Raspberry Pi Pico

MicroPython thermometer on a Pico: thermistor on GP26

MicroPython on a Raspberry Pi Pico: a 10k NTC thermistor and a 10k resistor on GP26, and the B equation, print the temperature every second. The whole build, a Raspberry Pi Pico and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $4.20. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • A voltage divider with a thermistor
  • NTC means resistance falls as it warms
  • Converting resistance to temperature with beta
  • Using the math module for a logarithm
  • Difficulty: Intermediate
  • Time: About 20 minutes
  • Board: Raspberry Pi Pico
  • Parts: 4

How it works

A 10k resistor goes to 3.3 V and a 10k NTC thermistor goes to ground, with GP26 at the point between them. As it warms, the thermistor's resistance falls, and so does the voltage on GP26.

Each second the program turns the reading into volts, then into the thermistor's resistance in ohms, then uses the beta equation with B of 3950 and 10k at 25 degrees C to find the temperature. It prints degrees Celsius.

Parts list

4 parts, plus the jumper wires. They retail for about $4.20; on Mokxi they're free.

Kits that can build it

This starter kit has every part in the circuit. Each kit's page lists what else it can build.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Resistor, 10k Ω pin 2Raspberry Pi Pico pin GP26
Thermistor, 10k NTC pin 1Raspberry Pi Pico pin GP26
Resistor, 10k Ω pin 13.3 V
Thermistor, 10k NTC pin 2Ground

The code

The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.

main.py · Raspberry Pi Pico
# A thermometer: a 10k NTC thermistor from GP26 to ground and a 10k from
# 3.3 V. The reading gives the thermistor's resistance, and the B
# equation (B = 3950, 10k at 25 C) turns that into a temperature.
from machine import ADC
import math
import time

sensor = ADC(26)

while True:
    volts = sensor.read_u16() * 3.3 / 65535
    ohms = 10000 * volts / (3.3 - volts)
    kelvin = 1 / (1 / (273.15 + 25) + math.log(ohms / 10000) / 3950)
    print("%.1f C" % (kelvin - 273.15))
    time.sleep(1)

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The temperature is far off. This project
    The math assumes a 10k fixed resistor and a 10k thermistor with a beta of 3950. Check the parts match.
  • The reading never changes. This project
    Check that GP26 connects to the point between the resistor and the thermistor.
  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The temperature reads far off or jumps around. Thermistor
    Use a fixed resistor equal to the thermistor's 10k at 25 C in the divider. Convert with the Steinhart-Hart or Beta equation (Beta is about 3950 for common parts), not a straight line.
  • The reading goes the wrong way, or self-heating shifts it. Thermistor
    An NTC lowers its resistance as it warms, so the divider voltage moves with the wiring side. Check which side the thermistor is on. Keep current small, with 3.3 V or 5 V through 10k, so it does not self-heat.
  • The Pico does not show up as a drive, or the program will not load. Raspberry Pi Pico
    Hold the BOOTSEL button while you plug in USB. A drive named RPI-RP2 appears. Then copy the UF2 file onto it.
  • A 5 V signal or sensor is wired to a GPIO pin. Raspberry Pi Pico
    Pico GPIO pins are 3.3 V only and are not 5 V tolerant. Use a level shifter or a voltage divider for any 5 V output going into the board.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.