Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi 4B-Based Smart Security System with Fingerprint and Keypad Access Control

View and Edit Project In Cirkit DesignerImage of Raspberry Pi 4B-Based Smart Security System with Fingerprint and Keypad Access Control

Circuit Documentation

Summary

This circuit is designed to interface with a Raspberry Pi 4B and includes various components such as a membrane matrix keypad, servo motor, relay module, power supply, ESP32-CAM, fingerprint scanner, LEDs, loudspeaker, microphone, push switch, solenoid lock, buck converter, and resistors. The circuit appears to be part of a security or access control system, utilizing a Raspberry Pi 4B as the central processing unit. The system features methods for user interaction and feedback, including a keypad, fingerprint scanner, visual indicators (LEDs), and audio output (loudspeaker). The Raspberry Pi controls a servo motor and a solenoid lock through a relay, likely for physical access control.

Component List

Wiring Details

Raspberry Pi 4B

4X4 Membrane Matrix Keypad

Servo

1 Channel 5V Relay Module

12V Power Supply

ESP32-CAM

Fingerprint Scanner

LED: Two Pin (Red and Green)

Loudspeaker

Condenser Microphone

2Pin Push Switch

12V Solenoid Lock

Buck Converter

Micro USB to Cable (2 Pin)

Documented Code

import RPi.GPIO as GPIO
import time
from pyfingerprint.pyfingerprint import PyFingerprint
from picamera import PiCamera
import os
import serial

# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Define pin numbers for components
green_led = 25
red_led = 8
servo_pin = 18
relay_pin = 23
doorbell_pin = 10
buzzer_pin = 7
keypad_rows = [5, 6, 13, 19]
keypad_cols = [12, 16, 20, 21]

# Set up GPIO pins
GPIO.setup(green_led, GPIO.OUT)
GPIO.setup(red_led, GPIO.OUT)
GPIO.setup(servo_pin, GPIO.OUT)
GPIO.setup(relay_pin, GPIO.OUT)
GPIO.setup(doorbell_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(buzzer_pin, GPIO.OUT)

# Servo setup
servo = GPIO.PWM(servo_pin, 50)  # 50Hz frequency
servo.start(0)

# Set up the fingerprint sensor (modify serial port as needed)
fingerprint_sensor = PyFingerprint('/dev/ttyUSB0', 57600)

# Initialize camera
camera = PiCamera()
camera.rotation = 180

# Keypad matrix setup
keypad = [
    ['1', '2', '3', 'A'],
    ['4', '5', '6', 'B'],
    ['7', '8', '9', 'C'],
    ['*', '0', '#', 'D']
]

# Function to read keypad input (you will need to complete this for your keypad)
def get_key():
    # Placeholder for reading key from keypad
    pass

def authenticate_keypad():
    attempts = 3
    correct_code = "1234"
    while attempts > 0:
        entered_code = ""
        for _ in range(4):  # Assume 4-digit code
            entered_code += get_key()
        if entered_code == correct_code:
            unlock_door()
            return True
        attempts -= 1
        time.sleep(1)
    lock_down()
    return False

def authenticate_fingerprint():
    attempts = 3
    while attempts > 0:
        try:
            print("Waiting for fingerprint...")
            if fingerprint_sensor.readImage():
                fingerprint_sensor.convertImage(0x01)
                result = fingerprint_sensor.searchTemplate()
                position_number = result[0]
                if position_number >= 0:
                    unlock_door()
                    return True
                else:
                    print("Fingerprint not recognized.")
            attempts -= 1
        except Exception as e:
            print("Error reading fingerprint: ", str(e))
    lock_down()
    return False

def unlock_door():
    GPIO.output(green_led, GPIO.HIGH)
    GPIO.output(relay_pin, GPIO.HIGH)
    play_tune(success=True)
    time.sleep(5)  # Keep the door unlocked for 5 seconds
    GPIO.output(green_led, GPIO.LOW)