import machine
import time
import math
ldr_pin = machine.ADC(26)
NTC_PIN = 26
NTC_RESISTANCE = 10000
NTC_BETA = 3950
def read_temperature():
adc = machine.ADC(NTC_PIN)
raw_value = adc.read_u16()
resistance = NTC_RESISTANCE / ((65535 / raw_value) - 1)
temperature = 1 / (1 / (273.15 + 25) + (1 / NTC_BETA) * math.log(resistance / 10000)) - 273.15
return temperature
while True:
temperature = read_temperature()
print("Temperature: {:.2f} °C".format(temperature))
time.sleep(1) # Delay for 1 second
ldr_value = ldr_pin.read_u16()
voltage = ldr_value * 3.3 / 65535
photoresistor_resistance = (10_000 * voltage) / (3.3 - voltage)
# Print the results
print("Photoresistor Resistance:", photoresistor_resistance, "Ω")
time.sleep(1)