import machine
import dht
import utime
# Setup DHT22 sensor
dht_pin = machine.Pin(15, machine.Pin.IN)
sensor = dht.DHT22(dht_pin)
# Setup LDR on ADC pin
ldr = machine.ADC(26)
while True:
try:
# Read temperature & humidity
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
# Read light level
light_value = ldr.read_u16() # 0 - 65535
light_percent = (light_value / 65535) * 100
print("🌡 Temp: {:.1f}°C 💧 Humidity: {:.1f}% ☀ Light: {:.1f}%".format(temp, hum, light_percent))
except Exception as e:
print("Sensor error:", e)
utime.sleep(2)