import network
import time
from machine import Pin, ADC
import dht
# ======================
# WIFI
# ======================
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect("Wokwi-GUEST", "")
API_URL = "https://script.google.com/macros/s/AKfycbyfes2l2RnT1fXpTmpyBtg5-kqjcGzokqxOeHzwCU1FVbS8bXvLDGKA_-BADfLIse4Cxg/exec"
while not wifi.isconnected():
time.sleep(1)
print("WiFi connected")
print("IP:", wifi.ifconfig()[0])
# ======================
# DHT22
# ======================
dht_pin = Pin(15)
dht_sensor = dht.DHT22(dht_pin)
# ======================
# LDR (ANALOG)
# ======================
ldr = ADC(Pin(34))
ldr.atten(ADC.ATTN_11DB) # range 0–3.3V
ldr.width(ADC.WIDTH_10BIT) # nilai 0–1023
# ======================
# LOOP
# ======================
while True:
try:
# baca DHT22
dht_sensor.measure()
suhu = dht_sensor.temperature()
kelembapan = dht_sensor.humidity()
# baca LDR
cahaya = ldr.read()
print("Suhu :", suhu, "°C")
print("Kelembapan :", kelembapan, "%")
print("Cahaya LDR :", cahaya, "*")
print("----------------------")
except Exception as e:
print("Error:", e)
time.sleep(2)