AI-Powered Smart Locker System Using Raspberry Pi With Face Recognition Security

by Chanchaldada in Circuits > Raspberry Pi

144 Views, 0 Favorites, 0 Comments

AI-Powered Smart Locker System Using Raspberry Pi With Face Recognition Security

ChatGPT Image Apr 29, 2026, 10_56_08 AM.png

Gone are those days, where locker were used to be dumb and you need to use lock and key and somebody had the manually assisgn you a locker and manage that with a register. Now you can use AI powered smart locker system using Raspberry Pi that will simply scan your face to unlock.

Here we have used computer vision and bundle it with Machine learning protocol like OpenCV, embedded all of that on Raspberry Pi chipset, add additional perpipherals like solenoid and relays.

The system combines Raspberry Pi, OpenCV, and a camera module to process facial recognition locally without needing cloud services, making it fast, reliable, and privacy-friendly. This project demonstrates how AI and embedded systems can be integrated to create practical smart security solutions for homes, offices, and industrial use cases.

Supplies

Supplies

  1. Raspberry Pi (3 / 4 / 5)
  2. MicroSD Card (16GB or higher with OS installed)
  3. Raspberry Pi Camera Module or USB Webcam
  4. Servo Motor (for locking mechanism)
  5. Jumper Wires
  6. Breadboard (optional)
  7. 5V Power Supply for Raspberry Pi
  8. External Power Supply (if needed for motor)
  9. Locker Box / Enclosure
  10. Laptop or PC (for setup and coding)

Materials / Components Required

IMG_3965 1.jpeg
IMG_3896 2.jpeg
relay.jpeg
picamera.JPG

To build the AI-Powered Smart Locker System with Face Detection using Raspberry Pi, you will need the following components:

  1. Raspberry Pi (3, 4, or 5 recommended)
  2. Raspberry Pi Camera Module or USB Webcam
  3. MicroSD Card (16GB or higher) with Raspberry Pi OS installed
  4. Servo Motor (for locking/unlocking mechanism)
  5. Electronic Door Lock or Solenoid Lock (optional based on design)
  6. Jumper Wires (Male-to-Female and Male-to-Male)
  7. Breadboard (for prototype connections)
  8. 5V Power Supply for Raspberry Pi
  9. External Power Source (if required for lock/servo)
  10. GPIO Expansion Board (optional, for easier connections)
  11. Wooden box / metal box (for making the actual locker body)
  12. Laptop/PC (for programming and setup)
  13. Internet connection (for installing libraries and updates)

Optional (for advanced features):

  1. Buzzer or LED indicators (for access status)
  2. Push button (manual override)
  3. RFID module (for hybrid security system)


Working Concept

The AI-Powered Smart Locker System with Face Detection using Raspberry Pi works by combining computer vision, AI-based face recognition, and an electronic locking mechanism to provide secure and automated access control.

When the system is powered on, the Raspberry Pi continuously accesses the camera feed in real time. Using the OpenCV library, it first detects a human face in the frame. Once a face is detected, the system compares it with the pre-registered authorized faces stored in its database.

If the face matches an authorized user, the system triggers a GPIO signal from the Raspberry Pi to activate the servo motor or electronic lock mechanism, unlocking the locker automatically for a few seconds. After that, the system re-locks itself to maintain security.

If the detected face does not match any registered user, access is denied and the locker remains locked. Optionally, the system can also trigger a buzzer or LED indicator to show an unauthorized access attempt.

This entire process runs locally on the Raspberry Pi, making the system fast, reliable, and independent of cloud services while ensuring user privacy and real-time response.

Circuit / Wiring Section

ChatGPT Image Apr 29, 2026, 11_52_52 AM.png
Image (16).jpg

The hardware setup of the AI-Powered Smart Locker System with Face Detection using Raspberry Pi is simple but needs careful GPIO connections for proper functioning of the camera and locking mechanism.

Camera Connection

  1. The Raspberry Pi Camera Module is connected directly to the CSI port of the Raspberry Pi.
  2. If using a USB webcam, it is connected to any available USB port.
  3. This camera is responsible for capturing live video feed for face detection.

Servo Motor / Lock Connection

  1. Servo Motor (or electronic lock) is connected to Raspberry Pi GPIO pins:
  2. Signal Pin → GPIO18 (or any PWM GPIO pin)
  3. VCC → 5V Pin on Raspberry Pi (or external supply if required)
  4. GND → Ground Pin on Raspberry Pi
  5. If using a solenoid lock, it should be connected through a relay module for safety:
  6. GPIO → Relay IN pin
  7. External power → Lock system
  8. Common GND shared between Raspberry Pi and relay

Optional Components Wiring

  1. Buzzer (optional):
  2. Positive → GPIO pin (e.g., GPIO17)
  3. Negative → GND
  4. LED Indicator (optional):
  5. Positive → GPIO pin with resistor
  6. Negative → GND
  7. Push Button (optional manual override):
  8. One side → GPIO pin
  9. Other side → GND

Power Supply

  1. Raspberry Pi is powered using a stable 5V power adapter.
  2. Servo/lock may require separate external power depending on load.
  3. Always ensure common ground (GND) between all components for proper signal communication.

This wiring setup ensures smooth communication between the Raspberry Pi, camera, and locking mechanism, enabling real-time AI-based access control.

Code Section

In this step, we will write the Python code for face detection and control the locking mechanism using Raspberry Pi GPIO.

First, create a new Python file:


nano smart_locker.py

Now copy and paste the following code:


import cv2
import RPi.GPIO as GPIO
import time

# GPIO Setup
SERVO_PIN = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(SERVO_PIN, GPIO.OUT)

pwm = GPIO.PWM(SERVO_PIN, 50)
pwm.start(0)

def unlock():
pwm.ChangeDutyCycle(7)
time.sleep(2)
pwm.ChangeDutyCycle(0)

def lock():
pwm.ChangeDutyCycle(2)
time.sleep(2)
pwm.ChangeDutyCycle(0)

# Load face detection model
face_cascade = cv2.CascadeClassifier(
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
)

# Start camera
cap = cv2.VideoCapture(0)

print("System Started...")

while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

if len(faces) > 0:
print("Face Detected - Unlocking")
unlock()
time.sleep(5)
lock()
else:
print("No Face Detected")

cv2.imshow('Camera Feed', frame)

if cv2.waitKey(1) & 0xFF == 27:
break

cap.release()
cv2.destroyAllWindows()
GPIO.cleanup()

Run the Code

After saving the file, run it using:


python3 smart_locker.py


Build Steps (Step-by-Step)

Image (15).jpg

Follow these steps to build your AI-Powered Smart Locker System with Face Detection using Raspberry Pi:

Step 1: Set Up Raspberry Pi

  1. Install Raspberry Pi OS on your microSD card
  2. Insert SD card and power on Raspberry Pi
  3. Connect to Wi-Fi and update system:

sudo apt update && sudo apt upgrade

Step 2: Enable Camera

  1. Open Raspberry Pi configuration:

sudo raspi-config

  1. Go to Interface Options → Camera → Enable
  2. Reboot the system

Step 3: Install Required Libraries

  1. Install OpenCV and required packages:

pip install opencv-python numpy

Step 4: Connect Hardware

  1. Connect camera (CSI port or USB)
  2. Connect servo motor to GPIO18
  3. Ensure proper VCC and GND connections
  4. (Optional) Connect buzzer/LED for indication

Step 5: Upload and Run Code

  1. Create a Python file:

nano smart_locker.py

  1. Paste the provided code
  2. Save and run:

python3 smart_locker.py

Step 6: Face Detection Setup

  1. System will start camera automatically
  2. When a face appears → it will be detected
  3. Servo motor will rotate to unlock locker

Step 7: Testing the System

  1. Stand in front of camera
  2. Check:
  3. Face detection working or not
  4. Servo unlocking properly
  5. Adjust camera angle if needed

Step 8: Final Assembly

  1. Place all components inside a box/locker
  2. Fix camera facing user
  3. Attach servo to locking mechanism
  4. Secure all wiring properly

Result

Your smart locker will now:

  1. Detect face in real-time
  2. Unlock automatically
  3. Lock again after a few seconds


Result / Demo

After completing the setup and running the code, the AI-Powered Smart Locker System works in real time using face detection.

What Happens in the Demo:

  1. As soon as the system starts, the camera begins capturing live video feed
  2. When a face appears in front of the camera, it is detected instantly
  3. The system processes the image and triggers the unlocking mechanism
  4. The servo motor rotates, unlocking the locker for a few seconds
  5. After the delay, the locker automatically locks again

Successful Output Includes:

  1. Face detected with a visible bounding box on screen
  2. Smooth and quick response time
  3. Servo motor unlocking and locking correctly
  4. No response when no face is detected

Demo Suggestions (Highly Recommended)

To make your project more professional on Instructables:

  1. Add real images of:
  2. Camera detecting face
  3. Locker in locked/unlocked state
  4. Record a short demo video showing:
  5. Face detection in action
  6. Automatic unlocking process

Final Outcome

The system successfully demonstrates how AI + Raspberry Pi + computer vision can be used to build a smart and secure access control solution for real-world applications like lockers, cabinets, and smart storage systems.

Conclusion

In this project, we successfully built an AI-Powered Smart Locker System with Face Detection using Raspberry Pi, demonstrating how artificial intelligence and embedded systems can be combined to create a smart and secure access control solution.

By integrating computer vision with hardware components like a camera and servo motor, the system is able to detect a human face in real time and automatically control the locking mechanism. This not only enhances security but also eliminates the need for traditional keys or passwords.

This project can be further improved by adding advanced features such as face recognition for authorized users only, mobile app integration, cloud monitoring, or multi-user access control, making it suitable for real-world applications in homes, offices, and industrial environments.

If you are looking to build custom IoT or Raspberry Pi-based solutions like this, you can explore professional development services here:

https://digitalmonk.biz/hire-raspberry-pi-developer/