from machine import ADC, Pin, PWM
import time
pir = Pin(2, Pin.IN)      
buzzer = Pin(3, Pin.OUT)   
doorswitch = Pin(4, Pin.IN, Pin.PULL_UP)  
pwm = PWM(buzzer) 
pwm.duty_u16(0) 

while True:
    pirstate = pir.value()      
    dooropen = doorswitch.value() == 0  
    if pirstate == 1 and not dooropen:
            buzzer.value(1)  
            pwm.freq(1000)
            pwm.duty_u16(32768)
            time.sleep(0.05)
    else:
        if dooropen or pirstate == 0:
            buzzer.value(0)  
            pwm.duty_u16(0)
            time.sleep(0.1)

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT