from machine import Pin, PWM
import time
# Pin definitions
pir_sensor = Pin(13, Pin.IN)
face_button = Pin(12, Pin.IN, Pin.PULL_UP)
finger_button = Pin(14, Pin.IN, Pin.PULL_UP)
red_led = Pin(2, Pin.OUT)
green_led = Pin(4, Pin.OUT)
buzzer = PWM(Pin(15))
def alert():
print("ALERT! Unknown Face Detected.")
red_led.value(1)
buzzer.freq(1000)
buzzer.duty_u16(30000)
time.sleep(3)
buzzer.duty_u16(0)
def fingerprint_alert():
print("Fingerprint Not Matched!")
red_led.value(1)
buzzer.freq(1500)
buzzer.duty_u16(30000)
time.sleep(5)
buzzer.duty_u16(0)
def access_granted():
print("Access Granted.")
red_led.value(0)
green_led.value(1)
time.sleep(3)
green_led.value(0)
print("AI Smart Door Security Initialized...")
while True:
motion = pir_sensor.value()
if motion:
print("Motion Detected!")
time.sleep(0.5)
# Face recognition simulation
if face_button.value() == 0:
print("Face Verified! Access Granted.")
access_granted()
else:
alert()
print("Photo Captured and Alert Sent!")
print("Waiting for Fingerprint Verification...")
time.sleep(0.5)
# Fingerprint simulation
if finger_button.value() == 0:
fingerprint_alert()
else:
access_granted()
else:
red_led.value(0)
green_led.value(0)
buzzer.duty_u16(0)
time.sleep(0.1)