from machine import Pin, PWM
from time import sleep
pir_pin = Pin(22, Pin.IN)
frequency = 5000
led = PWM(Pin(21), frequency)
while True:
if pir_pin.value():
print("Motion detected!")
led.duty(1023)
else:
print("No motion")
led.duty(150)
sleep(0.1)