# Define analog pin
thermistorPin = 0

# Define constants for voltage divider
R_DIV = 10000.0  # Value of the resistor in the voltage divider (10kΩ)
V_REF = 5.0      # Arduino's operating voltage (5V)

# Function to convert analog reading to temperature (in Celsius)
def analogToTemperature(analogReading):
    # Convert analog reading to voltage
    voltage = analogReading * V_REF / 1023.0
    
    # Calculate resistance of NTC based on voltage divider
    resistance_ntc = R_DIV * (V_REF / voltage - 1)
    
    # Steinhart-Hart equation coefficients
    A = 0.001129148
    B = 0.000234125
    C = 0.0000000876741
    
    # Calculate temperature using Steinhart-Hart equation
    inverse_temperature = A + B * math.log(resistance_ntc) + C * math.pow(math.log(resistance_ntc), 3)
    temperature = 1 / inverse_temperature - 273.15
    
    return temperature

# Setup function
def setup():
    pass

# Loop function
def loop():
    # Read analog value from thermistor
    analogValue = adc.read(thermistorPin)
    
    # Convert analog value to temperature
    temperature = analogToTemperature(analogValue)
    
    # Print temperature
    print("Temperature: {:.2f} °C".format(temperature))
    
    time.sleep(1)  # Delay for readability

Loading
pi-pico-w