Thermistor Temperature Sensing

In this section, we'll use a thermistor with the Raspberry Pi Pico 2 W. A thermistor is a variable resistor that changes its resistance based on temperature. The term comes from combining "thermal" and "resistor".

Types of Thermistors

Thermistors are categorized into two types:

Working Principle

Like the LDR, we use a thermistor in a voltage divider circuit. As temperature changes, the thermistor's resistance changes, which changes the output voltage. The Pico 2 W reads this voltage via ADC and we convert it to temperature using the B-parameter equation or Steinhart-Hart equation.

Hardware Requirements

B-Parameter Equation

The B-parameter equation converts resistance to temperature:

1/T = 1/T₀ + (1/B) × ln(R/R₀)

Where:

rust
const B_VALUE: f64 = 3950.0;
const REF_RES: f64 = 10_000.0; // 10kΩ
const REF_TEMP: f64 = 25.0; // 25°C

fn calculate_temperature(
    current_res: f64, 
    ref_res: f64, 
    ref_temp: f64, 
    b_val: f64
) -> f64 {
    let ln_value = libm::log(current_res / ref_res);
    let inv_t = (1.0 / ref_temp) + ((1.0 / b_val) * ln_value);
    1.0 / inv_t
}

fn kelvin_to_celsius(kelvin: f64) -> f64 {
    kelvin - 273.15
}

Circuit Connection

Connect the thermistor similar to the LDR circuit:

  1. One side of thermistor → AGND
  2. Other side → GPIO26 (ADC0)
  3. 10kΩ resistor between GPIO26 and ADC_VREF (3.3V)
Note

For Pico 2 W: If connecting with OLED display, use I2C1 (GPIO 18/19) to avoid conflicts with wireless GPIO pins.

Project: Temperature Display on OLED

In a complete project, you can read the temperature from the thermistor and display it on an OLED screen, showing ADC value, calculated resistance, and temperature in Celsius. This creates a practical digital thermometer!