from machine import Pin, PWM
from time import sleep
Sensor= Pin(2, Pin.IN)
Buzzer= PWM(Pin(3, Pin.OUT))
while True:
if Sensor.value() == 1:
Buzzer.freq(261)
Buzzer.duty_u16(32768)
sleep(1)
Buzzer.duty_u16(0)
else:
sleep(0.1)
Buzzer.duty_u16(0)