This is a comprehensive IoT-based safe lock system that combines motion detection, dynamic OTP generation, keypad authentication, and CCTV monitoring. The system is designed for power efficiency and security, using a Raspberry Pi as the central controller.
- Motion Detection: Uses an IR sensor to detect movement and automatically activate the system
- Dynamic OTP Generation: Generates random 7-character OTPs that change every 30 seconds
- Web-based OTP Display: Hosts a Flask server to display the current OTP via web interface
- IP-based Access Control: Restricts OTP access to whitelisted IP addresses only
- Keypad Authentication: 4x4 matrix keypad for OTP input
- Servo Motor Control: Automatically opens/closes a gate/lock mechanism
- CCTV Integration: Records video from a smartphone camera for surveillance
- Power-Efficient Activation: The IR sensor continuously monitors for motion. When detected, it triggers the Flask server for 30 seconds
- OTP Generation: A background thread generates random 7-character OTPs using characters 0-9 and A-D
- Web Interface: The Flask server displays the current OTP on a web page accessible only to whitelisted IPs
- User Authentication: Users enter the OTP via the 4x4 keypad
- Access Control: If the OTP matches, the servo motor rotates to open the gate for 30 seconds
- CCTV Recording: A separate script records video from a smartphone camera in 20-second intervals
- Raspberry Pi (any model with GPIO pins)
- IR sensor (motion detection)
- 4x4 matrix keypad
- Servo motor
- Smartphone (for CCTV functionality)
- Jumper wires and breadboard
Flask==2.0.1
RPi.GPIO==0.7.1
opencv-python==4.5.3.56
numpy==1.21.2
- Connect IR sensor to GPIO pin 23
- Connect VCC to 5V
- Connect GND to ground
- Row pins: GPIO 5, 6, 13, 19 (L1, L2, L3, L4)
- Column pins: GPIO 12, 16, 20, 21 (C1, C2, C3, C4)
- Connect servo signal wire to GPIO pin 2
- Connect VCC to 5V
- Connect GND to ground
-
Install Python dependencies:
pip install Flask RPi.GPIO opencv-python numpy
-
Clone or download the project files to your Raspberry Pi
-
Configure IP addresses:
- Edit
app.pyand update thewhitelisted_ipslist with your device IPs - Edit
cameraphone.pyand update theurlvariable with your smartphone's IP and port
- Edit
-
Configure CCTV recording directory:
- Edit
cameraphone.pyand update theoutput_dirpath
- Edit
-
Start the IR sensor monitoring:
python ir.py
This script runs continuously and monitors for motion detection.
-
Start the keypad authentication system:
python type1.py
This script waits for OTP input via the keypad.
-
Start the CCTV recording (optional):
python cameraphone.py
This script records video from your smartphone camera.
-
Motion Detection: When the IR sensor detects motion, it automatically starts the Flask server (
app.py) -
OTP Generation: The server generates a new 7-character OTP every 30 seconds and saves it to
otp.txt -
Web Access: Access the OTP by visiting
http://[RASPBERRY_PI_IP]:5000from a whitelisted device -
Keypad Input: Enter the 7-character OTP using the 4x4 keypad:
- Row 1: 1, 2, 3, A
- Row 2: 4, 5, 6, B
- Row 3: 7, 8, 9, C
- Row 4: *, 0, #, D
-
Access Control: If the OTP is correct, the servo motor rotates to open the gate for 30 seconds
-
Automatic Shutdown: The Flask server automatically stops after 30 seconds to save power
The CCTV system (cameraphone.py) provides continuous video recording:
- Connects to a smartphone camera stream
- Records video in 20-second segments
- Saves recordings with timestamps
- Stores files in the specified directory
- IP Whitelisting: Only authorized IP addresses can access the OTP
- Dynamic OTPs: OTPs change every 30 seconds
- Power Efficiency: Server only runs when motion is detected
- Automatic Timeout: Gate automatically closes after 30 seconds
- GPIO Permission Issues: Run with sudo or add user to gpio group
- Network Connectivity: Ensure all devices are on the same network
- IP Address Changes: Update whitelisted IPs if devices change
- Servo Motor Issues: Check wiring and power supply
- CCTV Connection: Verify smartphone IP and port settings
- All devices must be on the same network
- The system is designed for power efficiency with automatic shutdown
- CCTV recordings are stored locally on the Raspberry Pi
- The servo motor provides physical access control
- The system can be extended with additional sensors and features