Skip to content

itsA-D/Dynamic_AccessLock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic Password Generation for Safe Lock System

Project Description

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

workings :

  1. Power-Efficient Activation: The IR sensor continuously monitors for motion. When detected, it triggers the Flask server for 30 seconds
  2. OTP Generation: A background thread generates random 7-character OTPs using characters 0-9 and A-D
  3. Web Interface: The Flask server displays the current OTP on a web page accessible only to whitelisted IPs
  4. User Authentication: Users enter the OTP via the 4x4 keypad
  5. Access Control: If the OTP matches, the servo motor rotates to open the gate for 30 seconds
  6. CCTV Recording: A separate script records video from a smartphone camera in 20-second intervals

Dependencies

Hardware Requirements:

  • Raspberry Pi (any model with GPIO pins)
  • IR sensor (motion detection)
  • 4x4 matrix keypad
  • Servo motor
  • Smartphone (for CCTV functionality)
  • Jumper wires and breadboard

Software Dependencies:

Flask==2.0.1
RPi.GPIO==0.7.1
opencv-python==4.5.3.56
numpy==1.21.2

Installation and Setup

1. Hardware Connections

IR Sensor Connection:

  • Connect IR sensor to GPIO pin 23
  • Connect VCC to 5V
  • Connect GND to ground

4x4 Keypad Connection:

  • Row pins: GPIO 5, 6, 13, 19 (L1, L2, L3, L4)
  • Column pins: GPIO 12, 16, 20, 21 (C1, C2, C3, C4)

Servo Motor Connection:

  • Connect servo signal wire to GPIO pin 2
  • Connect VCC to 5V
  • Connect GND to ground

2. Software Installation

  1. Install Python dependencies:

    pip install Flask RPi.GPIO opencv-python numpy
  2. Clone or download the project files to your Raspberry Pi

  3. Configure IP addresses:

    • Edit app.py and update the whitelisted_ips list with your device IPs
    • Edit cameraphone.py and update the url variable with your smartphone's IP and port
  4. Configure CCTV recording directory:

    • Edit cameraphone.py and update the output_dir path

Usage Instructions

Running the Complete System

  1. Start the IR sensor monitoring:

    python ir.py

    This script runs continuously and monitors for motion detection.

  2. Start the keypad authentication system:

    python type1.py

    This script waits for OTP input via the keypad.

  3. Start the CCTV recording (optional):

    python cameraphone.py

    This script records video from your smartphone camera.

System Workflow

  1. Motion Detection: When the IR sensor detects motion, it automatically starts the Flask server (app.py)

  2. OTP Generation: The server generates a new 7-character OTP every 30 seconds and saves it to otp.txt

  3. Web Access: Access the OTP by visiting http://[RASPBERRY_PI_IP]:5000 from a whitelisted device

  4. 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
  5. Access Control: If the OTP is correct, the servo motor rotates to open the gate for 30 seconds

  6. Automatic Shutdown: The Flask server automatically stops after 30 seconds to save power

CCTV Functionality

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

Security Features

  • 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

Troubleshooting

  1. GPIO Permission Issues: Run with sudo or add user to gpio group
  2. Network Connectivity: Ensure all devices are on the same network
  3. IP Address Changes: Update whitelisted IPs if devices change
  4. Servo Motor Issues: Check wiring and power supply
  5. CCTV Connection: Verify smartphone IP and port settings

Notes

  • 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

About

A Flask-based IoT application for dynamic OTP generation and secure access control, designed for safe lock systems using Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors