Raspberry Pi Pico - NTC Thermistor Temperature Sensor

The RP2040 chip on a Raspberry Pi Pico already has a small temperature sensor inside, on ADC channel 4. But that sensor only knows how warm the chip itself is. It cannot tell you the temperature of the water in an incubator tray, a jar of yogurt that is fermenting, or the soil in a greenhouse. For jobs like these, you need a sensor at the end of a cable. The 10K NTC thermistor probe is the simplest one: a steel tip, two wires, and no chip at all.

In this guide, we will learn to set up and use a waterproof NTC thermistor temperature sensor (10K, B value 3950) on the Raspberry Pi Pico. We will cover the following details:

https://newbiely.com/images/cover/raspberry-pi-pico-ntc-thermistor-temperature-sensor.jpg

Hardware Preparation

1×Raspberry Pi Pico W
1×Raspberry Pi Pico Alternatively,
1×Micro USB Cable
1×NTC Thermistor Waterproof Probe 10K 3950 (10K resistor included)
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Raspberry Pi Pico

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of NTC Thermistor Temperature Sensor

Picture a short metal pencil on a cable: that is the probe. Its round-ended steel tip, 5mm across and 25mm long, holds the thermistor and keeps water out. From the tip, 0.5m of black cable leads to a small white JST XH2.54 connector with two openings. You do not need any adapter board, because the pins of male jumper wires fit right into those openings. DIYables sells the probes five at a time, and the bag has one 10K resistor for each probe.

10K NTC thermistor probe from DIYables - steel tip, black cable and white JST connector
image source: diyables.io
DIYables NTC Thermistor Probe (10K, 3950)
Element NTC thermistor (Negative Temperature Coefficient)
Resistance at 25°C 10kΩ, ±1% tolerance
Beta (B) Constant 3950
Range -20°C to +105°C
Probe round-ended steel tip (5mm x 25mm), waterproof
Cable Length 0.5m (black, two wires)
End Plug white JST XH2.54 with 2 openings
Kit Contents 5 probes, 5 resistors of 10K

Both wires of the probe are equal. Current can flow through a thermistor either way, just like through any other resistor, so you can swap them.

  • First wire (either one): connect to the 3.3 volts output of the Pico, 3V3(OUT).
  • Second wire: connect to GP26, one of the analog input pins of the Pico.
  • 10K resistor (in the same bag as the probe): connect between GP26 and GND (0 volts).

So how does a resistor measure temperature? The part in the tip is a resistor made to change its value with heat: a change of a few degrees moves its ohms a lot. The name NTC comes from Negative Temperature Coefficient. Put simply: the warmer the tip, the fewer ohms it has. At 25°C, this probe has exactly 10000 ohms. The Pico cannot measure ohms, because its ADC only reads voltages. That is why the 10K resistor and the probe sit one after the other between 3.3 volts and GND, so that they share the 3.3 volts. Such a pair is known as a voltage divider. Heat the tip, and the probe's share shrinks, so GP26 rises. Cool it, and GP26 falls. The script measures the GP26 voltage, calculates the probe's ohms from it, and then the degrees.

Some values for this circuit on the Pico:

Temperature Probe Resistance Voltage on GP26 read_u16() Value
-10°C about 58.2kΩ 0.48V 9603
4°C about 27.3kΩ 0.89V 17576
15°C about 15.8kΩ 1.28V 25365
35°C about 6.5kΩ 2.00V 39705
70°C about 1.76kΩ 2.81V 55728

Notice that the ohms do not fall by the same amount for every degree. A straight-line rule would be wrong here, so ntc_thermistor.py relies on the B (beta) formula:

1/T = 1/T0 + (1/B) × ln(R/R0)

Here R is the probe resistance that the Pico just measured, R0 is 10000 ohms, T0 is 298.15 kelvin (that is 25°C), and B is 3950. The formula works in kelvin, and subtracting 273.15 from T gives °C. A more precise relative of this formula exists, the three-constant Steinhart-Hart equation; with this probe, though, the one-constant beta version is plenty. Near 20°C to 25°C, a reading is normally no more than about 1°C away from the truth. The true value of your 10K resistor and the Pico's ADC cause most of that difference.

Wiring Diagram

Unlike the bigger Raspberry Pi computers, the Pico has its own ADC, so the probe needs no extra module. Only GP26, GP27 and GP28 can read an analog voltage, and here we use GP26 (ADC0), which is pin 31.

Raspberry Pi Pico NTC thermistor probe wiring, 10K resistor from GP26 to GND

This image is created using Fritzing. Click to enlarge image

Circuit Part Raspberry Pi Pico
Probe wire (either one) 3V3(OUT) (pin 36)
Other probe wire GP26 / ADC0 (pin 31)
10K resistor, first leg GP26 / ADC0 (pin 31)
10K resistor, second leg GND (pin 28)

The Pico sits in the breadboard, so every pin has free holes in its own column (the green holes in the drawing). The 10K resistor goes into the same breadboard, one row above the bottom row: one leg in the column of GP26 (pin 31), the other in the column of GND (pin 28), three columns to the left. No GND wire is needed. The jumpers start in the bottom row. From the GP26 column, a yellow jumper goes straight down to one opening of the white plug; from the 3V3(OUT) column (pin 36), a red jumper goes to the other opening.

※ NOTE THAT:

Take the probe's power from 3V3(OUT), never from VBUS or VSYS. In hot water, the probe falls to a few hundred ohms, and GP26 rises almost to the supply voltage. With about 5 volts from USB, that would be too much for the analog pin. There is a second reason: the Pico's ADC measures against the same 3.3 volts (ADC_VREF). When the divider and the ADC share one supply, the script only needs the ratio of the reading to 65535, and a small change in the 3.3 volts cancels out.

Raspberry Pi Pico Code - NTC Thermistor Temperature Sensor

The function read_gp26() reads GP26 ten times, 10 ms apart, and returns the average. The Pico's ADC has 12 bits, but MicroPython's read_u16() stretches the result to a number from 0 to 65535. The line ntc_ohms = FIXED_OHMS * (65535 / raw - 1) turns that number into the probe's ohms. Then math.log(), which is the natural log (ln) in MicroPython, puts the ohms into the beta formula. Before any math, the script checks for a reading near 0 (no probe) or near 65535 (a short), so it prints a hint instead of stopping with an error.

""" This Raspberry Pi Pico MicroPython code was developed by newbiely.com This Raspberry Pi Pico code is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-ntc-thermistor-temperature-sensor """ from machine import ADC, Pin import math import time # GP26 (ADC0, pin 31) is the point between the thermistor and the 10K resistor ntc_adc = ADC(Pin(26)) FIXED_OHMS = 10000 # the 10K resistor from the kit, between GP26 and GND R_25C = 10000 # thermistor resistance at 25 °C T_25C = 298.15 # 25 °C written in kelvin BETA = 3950 # B value of the probe SAMPLES = 10 # readings to average for one result def read_gp26(): # One read_u16() value jumps a little, so take the average of several total = 0 for _ in range(SAMPLES): total += ntc_adc.read_u16() time.sleep_ms(10) return total // SAMPLES while True: raw = read_gp26() # 0 = 0 volts, 65535 = 3.3 volts if raw < 1000: # Only the 10K resistor is holding GP26 down: the probe is not there print("u16 avg {:5d} | no thermistor found, check the plug and the 3V3(OUT) wire".format(raw)) elif raw > 65000: # GP26 sits at 3.3 volts: probe wires touching, or the 10K resistor is missing print("u16 avg {:5d} | reading at the top, check for a short or a missing 10K resistor".format(raw)) else: # The thermistor is on the 3.3 V side of the divider, so: ntc_ohms = FIXED_OHMS * (65535 / raw - 1) # B (beta) formula: 1/T = 1/T0 + ln(R/R0) / B, with T in kelvin inv_kelvin = 1 / T_25C + math.log(ntc_ohms / R_25C) / BETA temp_c = 1 / inv_kelvin - 273.15 temp_f = temp_c * 9 / 5 + 32 print("u16 avg {:5d} | NTC {:6.0f} ohm | {:5.1f} °C | {:5.1f} °F".format(raw, ntc_ohms, temp_c, temp_f)) time.sleep(1) # about one line per second

Detailed Instructions

Please follow these instructions step by step:

  • Ensure that Thonny IDE is installed on your computer.
  • Ensure that MicroPython firmware is installed on your Raspberry Pi Pico.
  • If this is your first time using a Raspberry Pico, refer to the Raspberry Pi Pico - Getting Started tutorial for detailed instructions.
  • Build the circuit as in the diagram: one probe wire to 3V3(OUT), the other probe wire to GP26, and the 10K resistor from GP26 to GND.
  • Connect the Raspberry Pi Pico to your computer using a USB cable.
  • Launch the Thonny IDE on your computer.
  • On Thonny IDE, select MicroPython (Raspberry Pi Pico) Interpreter by navigating to Tools Options.
  • In the Interpreter tab, select MicroPython (Raspberry Pi Pico) from the drop-down menu.
  • Ensure the correct port is selected. Thonny IDE should automatically detect the port, but you may need to select it manually (e.g., COM3 on Windows or /dev/ttyACM0 on Linux).
  • Copy the above code and paste it to the Thonny IDE's editor.
  • Save the script to your Raspberry Pi Pico by:
    • Click the Save button, or use Ctrl+S keys.
    • In the save dialog, you will see two sections: This computer and Raspberry Pi Pico. Select Raspberry Pi Pico
    • Save the file as main.py
  • Click the green Run button (or press F5) to run the script. The script will execute.
  • For the test, fill a hot-water bottle with warm water from the tap (not boiling water). Let the probe measure the room for a few seconds. Then press the steel tip flat against the hot-water bottle and hold it there.
  • Watch the Shell at the bottom of Thonny:
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot MPY: soft reboot u16 avg 30037 | NTC 11818 ohm | 21.3 °C | 70.3 °F u16 avg 29955 | NTC 11878 ohm | 21.2 °C | 70.1 °F u16 avg 30128 | NTC 11752 ohm | 21.4 °C | 70.5 °F u16 avg 32696 | NTC 10044 ohm | 24.9 °C | 76.8 °F u16 avg 36743 | NTC 7836 ohm | 30.6 °C | 87.1 °F u16 avg 39813 | NTC 6461 ohm | 35.2 °C | 95.3 °F u16 avg 42043 | NTC 5588 ohm | 38.7 °C | 101.7 °F u16 avg 43398 | NTC 5101 ohm | 41.0 °C | 105.7 °F u16 avg 44228 | NTC 4818 ohm | 42.4 °C | 108.3 °F u16 avg 44662 | NTC 4674 ohm | 43.2 °C | 109.7 °F u16 avg 44887 | NTC 4600 ohm | 43.6 °C | 110.4 °F u16 avg 45015 | NTC 4558 ohm | 43.8 °C | 110.8 °F u16 avg 44979 | NTC 4570 ohm | 43.7 °C | 110.7 °F
MicroPython (Raspberry Pi Pico) • Board CDC @ COM29 ≡

Lines one to three were taken in the room: about 21.3°C. The probe shows about 11.8kΩ there, a bit more than 10kΩ, because the room is cooler than 25°C. When the tip touches the hot-water bottle, the reading jumps quickly at first and then climbs more and more slowly. It settles near 43.8°C after about ten seconds. This slow end is normal: the steel tip has to warm up all the way before the thermistor inside reaches the new temperature, so wait for a steady value before you trust it. Does the Shell say "no thermistor found"? Then GP26 sees only the 10K resistor: look for a jumper wire that slipped out of the white connector, or a loose 3V3(OUT) wire.

If you name your script main.py and save it to the root directory of the Raspberry Pi Pico, it will automatically run each time the Pico is powered on or reset.

Two tips for real projects. Water must stay away from everything except the steel tip: the connector, the breadboard and the Pico itself. And never use this probe above 105°C. For an oven or a grill, the Raspberry Pi Pico - MAX6675 Thermocouple Module tutorial is the right choice. If you would rather have a waterproof sensor that converts the reading itself and simply gives you degrees, see the Raspberry Pi Pico - Temperature Sensor tutorial with the DS18B20.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!