from machine import ADC
import time
# Internal temperature sensor is connected to ADC channel 4
temp_sensor = ADC(4)
def read_internal_temperature():
# Read the raw ADC value
adc_value = temp_sensor.read_u16()
# Convert ADC value to voltage
voltage = adc_value * (3.3 / 65535.0)
# Temperature calculation based on sensor characteristics
temperature_celsius = 27 - (voltage - 0.706) / 0.001721
return temperature_celsius
def celsius_to_fahrenheit(temp_celsius):
temp_fahrenheit = temp_celsius * (9/5) + 32
return temp_fahrenheit
while True:
temperatureC = read_internal_temperature()
temperatureF = celsius_to_fahrenheit(temperatureC)
print("Internal Temperature:", temperatureC, "°C")
print("Internal Temperature:", temperatureF, "°F")
time.sleep(2)