Table of Contents
NTC Readout (micropython) #
We wire the circuit on the Breadboard and connect it to the Raspberry Pi Pico device.
In the MicroPython code we need to do the following steps:
- We measure Vout using the ADC on Raspberry Pi Pico
- We calculate Rt using the Voltagee Divider Equation
- Then we use Steinhart-Hart equation for finding the Temperature
- Finally we convert from degrees Kelvin to Celsius
MicroPython Code Eeample for reading and calculation the Temperature Value from a Thermistor:
from machine import ADC
from time import sleep
import math
adcpin = 28
thermistor = ADC(adcpin)
# Voltage Divider
Vin = 3.3
Ro = 10000 # 10k Resistor
# Steinhart Constants
A = 0.001129148
B = 0.000234125
C = 0.0000000876741
while True:
# Get Voltage value from ADC
adc = thermistor.read_u16() >> 4 # Get original 12-bit value 0-4096
print ("ADC Value:", adc)
Vout = (3.3/4096) * adc
# Calculate Resistance
Rt = (Vout * Ro) / (Vin - Vout)
#Rt = 10000 # Used for Testing. Setting Rt=10k should give TempC=25
# Steinhart - Hart Equation
TempK = 1 / (A + (B * math.log(Rt)) + C * math.pow(math.log(Rt), 3))
# Convert from Kelvin to Celsius
TempC = TempK - 273.15
#Correction for %5
TempC = TempC - 7
print(round(TempC, 1))
sleep(1)
Products #
Source #
https://halvorsen.blog/documents/technology/iot/pico/pico_thermisor.php