Custom Temperature Sensor

Thermistor

Input Analog

Changes its electrical resistance with temperature. Can be used to estimate the current temperature and detect changes.


Basic Usage

Relies on the adafruit_thermistor library. If it is not already included in your lib folder, it is available for download with the 10.x bundle.

# --- Imports
import time
import board
import adafruit_thermistor 

# --- Variables
# Initialize analog input connected to temperature sensor
resistor = 10000
resistance = 10000
nominal_temp = 25
b_coefficient = 3950

# Connect the temperature sensor to pin A2 
temp_sensor = board.A2

# --- Functions

# Library function to read the temperature sensor accurately
thermistor = adafruit_thermistor.Thermistor(
    temp_sensor, resistor, resistance, nominal_temp, b_coefficient
)

# --- Setup

# --- Main loop
while True:
    celsius = thermistor.temperature
    fahrenheit = (celsius * 9 / 5) + 32
    print("== Temperature ==\n{} *C\n{} *F\n".format(celsius, fahrenheit))
    time.sleep(0.5)

This site uses Just the Docs, a documentation theme for Jekyll.