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:
- NTC (Negative Temperature Coefficient):
- Resistance decreases as temperature increases
- Used for temperature sensing and inrush current limiting
- We'll use NTC thermistors in our exercises
- PTC (Positive Temperature Coefficient):
- Resistance increases as temperature rises
- Used as resettable fuses for overcurrent protection
- Common in battery chargers and medical devices
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
- NTC 103 Thermistor - 10K OHM, 5mm epoxy coated disc
- 10kΩ Resistor - For voltage divider
- Jumper wires
B-Parameter Equation
The B-parameter equation converts resistance to temperature:
Where:
- T = Temperature in Kelvin
- T₀ = Reference temperature (typically 298.15K or 25°C)
- R = Current resistance
- R₀ = Reference resistance (typically 10kΩ at 25°C)
- B = B-value constant (typically 3950 for common thermistors)
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:
- One side of thermistor → AGND
- Other side → GPIO26 (ADC0)
- 10kΩ resistor between GPIO26 and ADC_VREF (3.3V)
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!