# Motion Sensor to detect pet
import machine
import utime
# Define PIR sensor pin
pir_pin = machine.Pin(16, machine.Pin.IN)
# Function to detect motion
def detect_motion():
return pir_pin.value()
# Function to wait for motion
def wait_for_motion():
print("Waiting for motion...")
while not detect_motion():
utime.sleep(1)
# Loop for when pet is detected
while True:
wait_for_motion()
print("Pet detected!")
utime.sleep(1)