import time
from math import log
from machine import Pin, ADC, PWM
led_1 = Pin(0, Pin.OUT)
buzzer = Pin(3, Pin.OUT)
temp_sensor = ADC(26)
light_sensor = ADC(27)
def adc_to_C(x):
return(1 / (log(1/(65535/x - 1))/3950 +1/298.15) - 273.15)
while True:
digital_val = temp_sensor.read_u16()
analog_val = float ((digital_val/(65535-1)) *3.3)
temperature = adc_to_C(digital_val)
photo_val = light_sensor.read_u16()
light = round(photo_val/65535*100,2)
if temperature > 30:
led_1.value(analog_val)
else:
led_1.value(0)
if light > 50:
buzzer.value(1)
else:
buzzer.value(0)
time.sleep(0.2)