top of page

Raspberry Pi Pico with Thermistor

A thermistor is a resistance thermometer, or a resistor whose resistance is dependent on temperature. The name is a combination of "thermal" and "resistor". It is made of metallic oxides, pressed into a bead, disk, or cylindrical shape and then encapsulated
with an impermeable material such as epoxy or glass.

thermistor.jpg
Symbol-of-Thermistor.jpg

Some common applications of the thermistor include: digital thermometers, used in cars to measure oil and coolant temperatures, in household appliances such as ovens and refrigerators, also found in any application that requires heating cooling protection circuits for safe operations.

​

Unlike other sensors, the thermistor doesn't actually read temperature, rather the resistance of a thermistor changes with temperature. The level of temperature depends on the material used in the thermistor. In addition to thermistor, several other types of
temperature sensors are used. The most common types being: Resistance Temperature Detector (RTD) and integrated circuits (IC), such as the LM35 and AD590. The thermistor and LM35 are commonly used with the Arduino. Common differences between these two include: thermistor is more durable, smaller in size, less expensive, highly sensitive, and best for measuring single point temperature. While the LM35 provides linear output (i.e, the voltage is equivalent to the resistance) which thermistor does not. Thermistor also has slow response time. 

thernistor log-graph.png

Because the thermistor is a variable resistor, we need to measure the resistance before we calculate the temperature. But the Arduino can only measure voltage and not resistance directly. So, the Arduino will measure the voltage at a point between the thermistor and a known resistor, known as voltage divider. In our case, the known resistance is 10K ohms, because we are using a 10K ohms thermistor.

 

Voltage divider equation:

84oaa1hPNO.png

where:
Vout = Voltage bewteen thermistor and known resistor.
Vin = Vcc (3.3V).
R1 = Known resistor value. 
R2 = Resistance of thermistor.

​

To find R2:

yDp05shv2C.png

Finally, the Steinhart-Hart equation is used to convert the resistance of the thermistor to a temperature reading.

HeW2PQHjsu.png

where:
T = temperature (in Kelvins).
R = resistance at T. (in ohms).
A, B, C are the Steinhart-Hart coefficients, which vary depending on the type and model of thermistor and the temperature range of interest. (Here we will replace A, B, C with c1, c2, and c3). This will be expanded in the code.

Schematic

​

Hardware components:

  • Raspberry Pi Pico.

  • Breadboard.

  • Thermistor (10K ohms)

  • Resistor (10K ohms).

  • Male-Male jumper wires.

Screenshot (104).png

Code

​

from machine import ADC, Pin
import utime
import math

​

#Variable declaration
logR2 = None
R2 = None
T = None
Tc = None
Tf = None

R1 = 10000
c1 = 1.009249522e-03
c2 = 2.378405444e-04
c3 = 2.019202697e-07

​

thermistorPin = machine.ADC(28)

​

while True:
    reading = thermistorPin.read_u16()

    R2 = R1 * (65535 / reading - 1.0);
    logR2 = math.log(R2);
    T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
    Tc = T - 273.15;
    Tf = (Tc * 9.0)/ 5.0 + 32.0;

    print("Temperature: ", Tc)
    print("Temperature: ", Tf)
    print(" ")
    utime.sleep(0.5)


The above sketch will read temperature using thermistor and display results in Fahrenheit and Celsius in the Shell section of Thonny IDE.

bottom of page