Your comprehensive guide to deploying the Smart Door Lock System from scratch.
- Prerequisites
- Hardware Assembly
- Supabase Setup
- VPS Backend Deployment
- Telegram Bot Setup
- Raspberry Pi Configuration
- Testing & Verification
- Admin Management
- Troubleshooting
- Raspberry Pi 4 or 5 (recommended: 4GB RAM)
- 7-inch touchscreen display (800x480)
- R307 Fingerprint Sensor
- Pi Camera Module v2 (or compatible USB webcam)
- SG90 Servo Motor
- MicroSD card (32GB+, Class 10)
- Power supply (5V 3A)
- Jumper wires (M-F, 20+ pieces)
- Breadboard (optional, for prototyping)
- Supabase account (free tier works)
- VPS server (1GB RAM minimum)
- Domain/subdomain for backend
- Telegram account
- Basic Linux command line
- Understanding of GPIO pins
- SSH access knowledge
- Basic networking (optional for troubleshooting)
Connection:
R307 Sensor → Raspberry Pi
----------------------------------------
VCC (Red) → 5V (Pin 2 or 4)
GND (Black) → GND (Pin 6)
TX (White) → RX GPIO 15 (Pin 10)
RX (Green) → TX GPIO 14 (Pin 8)
Enable Serial Port:
sudo raspi-config
# 3. Interface Options → Serial Port
# Login shell: No
# Serial hardware: Yes
sudo rebootTest:
cd "Rasberry pi/fingerprint"
python3 test_serial.pyConnect:
- Insert ribbon cable into CSI port
- Blue side faces ethernet port
- Enable camera:
sudo raspi-config # 3. Interface Options → Camera → Enable sudo reboot
Test:
libcamera-hello
# or
raspistill -o test.jpgConnection:
Servo → Raspberry Pi
----------------------------------------
VCC (Red) → 5V (Pin 2)
GND (Brown) → GND (Pin 14)
Signal (Orange)→ GPIO 17 (Pin 11)
Test:
cd "Rasberry pi/servo"
python3 rotate.py7-inch DSI Touchscreen:
- Connect via DSI port
- Power via GPIO pins
- Should auto-detect on boot
USB Touchscreen:
- Just plug in via USB
- Calibrate if needed:
sudo apt install xinput-calibrator xinput_calibrator
- Go to https://supabase.com
- Sign in / Create account
- Click "New Project"
- Fill details:
- Name:
door-lock-system - Database Password: (save this!)
- Region: (closest to you)
- Name:
- Wait for project creation (~2 minutes)
- Go to SQL Editor (left sidebar)
- Click "New Query"
- Copy entire contents of
supabase/setup.sql - Paste and click "Run"
- Verify tables created:
- Go to Table Editor
- Should see: users, face_images, access_logs, model_metadata, system_settings, notifications
- Go to Project Settings → API
- Copy these values (you'll need them):
Project URL: https://xxxxx.supabase.co anon/public key: eyJhbGc... service_role key: eyJhbGc... (keep secret!) JWT Secret: (under JWT Settings)
For face images:
- Go to Storage → New Bucket
- Name:
face-images - Public: No
- Create
SSH to your VPS:
ssh user@your-domain.example.comUpdate system:
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip python3-venv git nginx -ycd ~
git clone https://github.com/sasukeuchiha14/fingerprint-camera-door-lock.git
cd fingerprint-camera-door-lock/Backendpip3 install -r requirements.txtRequired packages:
- flask
- flask-cors
- python-dotenv
- supabase
- face-recognition
- opencv-python
- numpy
- requests
nano .envAdd:
# Supabase Configuration
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_SERVICE_ROLE_KEY=eyJhbGc...your-service-role-key...
SUPABASE_JWT_SECRET=your-jwt-secret
# Telegram Bot
TELEGRAM_BOT_TOKEN=123456789:ABCdef...
TELEGRAM_ADMIN_CHAT_IDS= # Leave empty, managed via database now
# Backend URL (for self-reference)
BACKEND_URL=https://your-domain.example.com/doorlocksudo cp nginx.conf /etc/nginx/sites-available/doorlock
sudo ln -s /etc/nginx/sites-available/doorlock /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxOptional: SSL with Certbot
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your-domain.example.comTest run:
python3 server.py
# Should see: Running on http://0.0.0.0:7000Production (keep terminal open):
python3 server.pyOr use screen/tmux:
screen -S doorlock-backend
python3 server.py
# Press Ctrl+A, D to detach
# Reattach: screen -r doorlock-backend# From another terminal
curl http://localhost:7000/health
# Should return: {"status":"healthy","timestamp":"..."}
curl https://your-domain.example.com/doorlock/health
# Should also work via nginx- Open Telegram
- Search for
@BotFather - Send
/newbot - Choose name:
My Door Lock Bot - Choose username:
MyDoorLockBot(must end in 'bot') - Copy the token:
123456789:ABCdefgh...
- Search for
@userinfobot - Send
/start - Copy your chat ID:
123456789
On VPS:
cd ~/fingerprint-camera-door-lock/Telegram\ bot
nano .envAdd:
# Telegram Bot
TELEGRAM_BOT_TOKEN=123456789:ABCdefgh...your-token...
# Supabase
SUPABASE_URL=https://xxxxx.supabase.co
SUPABASE_SERVICE_ROLE_KEY=eyJhbGc...
# Backend
BACKEND_URL=https://your-domain.example.com/doorlockpip3 install -r requirements.txtTest:
python3 main.py
# Should see: Door Lock Telegram Bot is running...Production:
screen -S doorlock-telegram
python3 main.py
# Ctrl+A, D to detach- Open Telegram
- Search for your bot:
@MyDoorLockBot - Send
/start - Should receive welcome message
Flash OS:
- Download Raspberry Pi Imager
- Flash "Raspberry Pi OS with Desktop" to SD card
- Boot Pi and complete setup wizard
Update system:
sudo apt update && sudo apt upgrade -ysudo raspi-configEnable:
- Interface Options → Camera → Yes
- Interface Options → Serial Port → Shell: No, Hardware: Yes
- System Options → Boot → Desktop (for GUI)
Reboot:
sudo rebootcd ~/Desktop
git clone https://github.com/sasukeuchiha14/fingerprint-camera-door-lock.git
cd fingerprint-camera-door-lock/Rasberry\ pipip3 install -r requirements.txt --break-system-packagesThis installs:
- pygame
- face-recognition
- opencv-python
- adafruit-fingerprint
- picamera2
- gpiozero
- requests
- python-dotenv
nano .envAdd:
BACKEND_URL=https://your-domain.example.com/doorlock
TELEGRAM_BOT_USERNAME=MyDoorLockBotpython3 gui_app.pyShould see touchscreen interface with three buttons.
Method 1: Desktop Autostart
mkdir -p ~/.config/autostart
nano ~/.config/autostart/doorlock.desktopAdd:
[Desktop Entry]
Type=Application
Name=Door Lock GUI
Exec=python3 /home/pi/Desktop/fingerprint-camera-door-lock/Rasberry\ pi/gui_app.py
Terminal=falseMethod 2: systemd Service
sudo nano /etc/systemd/system/doorlock-gui.serviceAdd:
[Unit]
Description=Door Lock GUI
After=graphical.target
[Service]
Type=simple
User=pi
Environment="DISPLAY=:0"
WorkingDirectory=/home/pi/Desktop/fingerprint-camera-door-lock/Rasberry pi
ExecStart=/usr/bin/python3 gui_app.py
Restart=always
[Install]
WantedBy=graphical.targetEnable:
sudo systemctl enable doorlock-gui.service
sudo systemctl start doorlock-gui.serviceVia GUI:
- Tap "Create New User"
- Fill details:
- Name: Test User
- Email: test@example.com
- Phone: +1234567890
- PIN: 1234
- Tap "Next"
- Tap "Start Enrollment"
- Place finger on sensor 3-5 times
- Tap "Capture Image" 5 times (different angles)
- Tap "Complete & Train Model"
- Wait for model training (~2 minutes)
Verify:
# Check user in database
curl https://your-domain.example.com/doorlock/api/get-usersVia GUI:
- Tap "Link Telegram"
- Tap "I'm Ready - Generate PIN"
- Note the PIN
Via Telegram:
- Open bot:
@MyDoorLockBot - Send
/register - Bot sends 4-digit PIN
Back to GUI:
- Enter PIN from bot
- Tap "OK"
- Should show "Linked!"
Verify:
- Send
/statusto bot - Should respond with system status
- Tap "Unlock Door"
- Enter PIN: 1234
- Look at camera for face scan
- Place finger on sensor
- Should unlock!
Check Telegram:
- Should receive notification: "🔓 Door unlocked by Test User"
Via Supabase Dashboard:
- Go to app.supabase.com
- Select your project
- Table Editor →
users - Find user row
- Edit
is_admincolumn →true - Save
Send to Telegram bot:
/status → System health check
/logs → Recent 10 access logs
/users → All registered users
/stats → Door usage statistics
/retrain → Trigger model retraining
Only admins can use these commands.
"Connection refused"
# Check if backend is running
curl http://localhost:7000/health
# Check nginx
sudo systemctl status nginx
sudo nginx -t
# Check logs
tail -f /var/log/nginx/error.log"Import error: face_recognition"
# Install system dependencies
sudo apt install cmake build-essential -y
pip3 install dlib face-recognition"Fingerprint sensor not found"
# Check serial port
ls -l /dev/serial*
# Should show /dev/serial0
# Test serial
sudo minicom -D /dev/serial0 -b 57600
# Re-enable in raspi-config
sudo raspi-config"Camera not working"
# Test camera
libcamera-hello
# Check if enabled
vcgencmd get_camera
# Should show: supported=1 detected=1
# Re-enable
sudo raspi-config
# Interface Options → Camera → Yes
sudo reboot"Pygame not opening"
# Check display
echo $DISPLAY
# Should be :0
# Export if needed
export DISPLAY=:0
python3 gui_app.py"Touch not responding"
# List input devices
xinput list
# Calibrate touchscreen
sudo apt install xinput-calibrator
xinput_calibrator"Table does not exist"
-- Re-run schema in Supabase SQL Editor
-- Copy from supabase/setup.sql"RLS policy error"
-- Disable RLS for testing (not recommended for production)
ALTER TABLE users DISABLE ROW LEVEL SECURITY;"Bot not responding"
# Check bot is running
ps aux | grep main.py
# Check logs
# (check terminal where bot is running)
# Test bot token
curl https://api.telegram.org/bot<TOKEN>/getMe"Unauthorized error"
- Verify
TELEGRAM_BOT_TOKENin .env - Check token with BotFather
"Cloud unavailable"
- Check
BACKEND_URLin .env - Test:
curl https://your-domain.example.com/doorlock/health - Verify internet connection
"Model not found"
- Ensure model training completed
- Check
model_metadatatable in Supabase - Trigger retrain:
/retrainvia Telegram
"PIN expired"
- PINs expire after 10 minutes
- Generate new PIN via
/register
- Change all default passwords
- Enable SSL on backend (certbot)
- Enable RLS policies in Supabase
- Use strong Supabase service role key
- Don't commit
.envfiles to git - Restrict Supabase API access by IP (optional)
- Backend server has adequate resources (1GB+ RAM)
- Database has proper indexes (already in setup.sql)
- Face images are compressed
- Model file is optimized
- Set up Telegram notifications
- Test admin commands work
- Check access logs regularly
- Monitor backend uptime
- Set up database backups (Supabase auto-backup)
- Document admin users
- Keep dependencies updated
- Backup face model periodically
- Clean old access logs (optional)
- Test disaster recovery
# Start GUI
python3 gui_app.py
# Test fingerprint
python3 fingerprint/test_serial.py
# Test camera
libcamera-hello
# Check logs
journalctl -u doorlock-gui.service -f# Start backend
python3 server.py
# Check health
curl http://localhost:7000/health
# View users
curl https://your-domain.example.com/doorlock/api/get-users
# Reload nginx
sudo systemctl reload nginx# Start bot
python3 main.py
# User commands
/start
/register
# Admin commands
/status
/logs
/users
/stats
/retrain-- View all users
SELECT * FROM users;
-- View recent logs
SELECT * FROM access_logs ORDER BY timestamp DESC LIMIT 10;
-- Set admin
UPDATE users SET is_admin = true WHERE name = 'Your Name';
-- View active model
SELECT * FROM model_metadata WHERE is_active = true;- README.md - Project overview
- Backend/NGINX_SETUP.md - Nginx configuration
- .env.example - Environment template
Setup complete! Enjoy your smart door lock system! 🎉