import machine
import time
import dht
#==========================================
#STEP 1: ALIGN YOUR HARDWARE PINS
#==========================================
#:Look at your simulator canvas! Change these numbers to match your wires
DHT_PIN_NUMBER = 15 # Put the pin number where your DHT sensor wire is connected
#Telling the ESP32 chip where the parts are plugged in
sensor = dht.DHT22(machine.Pin(DHT_PIN_NUMBER))
#==========================================
#STEP 2: SET YOUR THRESHOLD (MAGIC BOUNDARY)
#==========================================
#This is the exact limit or number boundary that triggers our automatic system
TEMPERATURE_THRESHOLD = 30
print("--- Smart City Automation System Started ---")
#==========================================
#STEP 3: THE AUTOMATION LOOP
#==========================================
:while True
try:
# Ask the sensor to check the air temperature
sensor.measure()
current_temp = sensor.temperature()
# IF/THEN Logic: Has the temperature crossed our threshold boundary?
if current_temp > TEMPERATURE_THRESHOLD:
print("⚠ Alert! Threshold limit crossed!")
else:
# Print the current number so we can see it on screen
print("Live Temperature Reading:", current_temp, "°C")
except OSError as e:
# If something goes wrong, give a friendly troubleshooting hint
print("Error: Cannot read sensor data. Check your wire connections!")
# Rest for 2 seconds before taking the next temperature reading
time.sleep(2)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4