🐹 Tutorial 12 - Thermometer

Thermistors are electronic components that change their resistance in response to temperature changes. The Thermistor MF11-103 10K ohm is a type of thermistor that has a resistance of 10,000 ohms at 25°C (room temperature). As the temperature increases or decreases, the resistance of the thermistor will change accordingly.

The MF11-103 10K ohm thermistor is commonly used in temperature sensing applications, such as monitoring the temperature of a room, controlling the temperature of an oven or a refrigerator, or measuring the temperature of a liquid in a laboratory experiment. It can also be used in combination with other electronic components to create a temperature sensor or a thermostat.

In order to use the MF11-103 10K ohm thermistor, you will need to connect it to a circuit and measure its resistance at different temperatures. You can use a microcontroller like the Raspberry Pi Pico with MicroPython to read the resistance of the thermistor and convert it into a temperature reading.

Overall, the MF11-103 10K ohm thermistor is a versatile and reliable component for temperature sensing applications, and can be easily integrated into a variety of projects.

Components Needed

ComponentQuantity
Raspberry Pi Pico W1
Micro USB Cable1
Breadboard1
WiresSeveral
Resistor1 - 10KΩ
Thermistor1

Fritzing Diagram

Code

import machine
import utime
import math

thermistor = machine.ADC(28)

while True:
    temperature_value = thermistor.read_u16()
    Vr = 3.3 * float(temperature_value) / 65535
    Rt = 10000 * Vr / (3.3 - Vr)
    temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
    Cel = temp - 273.15
    Fah = Cel * 1.8 + 32
    print ('Celsius: %.2f C  Fahrenheit: %.2f F' % (Cel, Fah))
    utime.sleep_ms(200)

Code Explanation

Importing necessary modules:

import machine
import utime
import math

The code imports the machine module, which is typically used for interacting with hardware on microcontrollers, the utime module, which is used for time-related operations, and the math module, which provides mathematical functions.

Setting up the thermistor pin:

thermistor = machine.ADC(28)

The code sets up an ADC (Analog-to-Digital Converter) object for the thermistor using pin number 28.

Reading thermistor value and calculating temperature:

while True:
    temperature_value = thermistor.read_u16()
    Vr = 3.3 * float(temperature_value) / 65535
    Rt = 10000 * Vr / (3.3 - Vr)
    temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
    Cel = temp - 273.15
    Fah = Cel * 1.8 + 32
    print ('Celsius: %.2f C  Fahrenheit: %.2f F' % (Cel, Fah))
    utime.sleep_ms(200)

The code enters an infinite loop and reads the value of the thermistor using the read_u16() method, which reads the analog value as a 16-bit unsigned integer. It stores the value in the temperature_value variable. The code then calculates the thermistor resistance (Rt) using the formula based on the voltage (Vr) calculated from the ADC value. Next, it calculates the temperature in Celsius (Cel) using the Steinhart-Hart equation, which relates the resistance of the thermistor to the temperature. Finally, it converts the temperature from Celsius to Fahrenheit (Fah) and prints both values using the print() function with formatted string. The code sleeps for 200 milliseconds using the utime.sleep_ms() method, providing a delay to avoid continuous reading and processing of thermistor values.