Built-in project · Raspberry Pi Pico W

Pico W thermistor thermometer on GP28

MicroPython on a Pico W: a 10k thermistor divider on GP28, its resistance turned into Celsius and Fahrenheit with the beta equation, once a second. The whole build, a Raspberry Pi Pico W 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.

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

The parts retail for about $6.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
  • Celsius, Fahrenheit and Kelvin
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Raspberry Pi Pico W
  • Parts: 4

How it works

A 10k resistor goes to 3.3 V and a 10k NTC thermistor goes to ground, with GP28 at the point between them. As the temperature rises, the thermistor's resistance drops, so the voltage at GP28 drops.

Each second the program reads that voltage, works out the thermistor's resistance, and uses the beta equation to find the temperature. It then prints degrees Celsius and Fahrenheit.

Parts list

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

Kits that can build it

These 2 starter kits have 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 W pin GP28
Thermistor, 10k NTC pin 1Raspberry Pi Pico W pin GP28
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 W
# Thermometer: a 10k from 3.3 V and the 10k thermistor to ground, the
# middle on GP28. From the reading, the thermistor's resistance; from the
# resistance, the temperature, with its beta of 3950.
from machine import ADC
import math
import time

sensor = ADC(28)
BETA = 3950
R25 = 10000          # the thermistor's resistance at 25 C

while True:
    v = sensor.read_u16() / 65535 * 3.3
    r = 10000 * v / (3.3 - v)
    kelvin = 1 / (1 / 298.15 + math.log(r / R25) / BETA)
    c = kelvin - 273.15
    f = c * 9 / 5 + 32
    print("%.1f C  %.1f F" % (c, f))
    time.sleep(1)

Troubleshooting

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

  • The temperature is far off. This project
    Check the values BETA (3950) and R25 (10000) match your thermistor, and the fixed resistor is 10k.
  • The reading never changes. This project
    Check that GP28 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.
  • Pins are powered from 5 V, or a 5 V signal goes into a GPIO. The RP2040 pins are 3.3 V only and are not 5 V tolerant. Raspberry Pi Pico W
    Power the board from VBUS or VSYS at 5 V, but keep GPIO signals at 3.3 V. Use a level shifter or a divider for 5 V parts.
  • WiFi code fails to connect, or the on-board LED code does nothing. The LED on the Pico W is not on GP25 like on the plain Pico. Raspberry Pi Pico W
    Use the board's LED_BUILTIN name so the library drives it through the WiFi chip. Join a 2.4 GHz network only, with the right SSID and password, and wait for the link before sending.

Change it and keep it

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