https://github.com/arrajkamel/motiondetectionsecuritysystem
An Arduino-based motion detection security system with password protection, FSM-driven behavior, and modular design for home automation and IoT applications.
https://github.com/arrajkamel/motiondetectionsecuritysystem
arduino cpp infrared-sensor motion-sensor
Last synced: 2 months ago
JSON representation
An Arduino-based motion detection security system with password protection, FSM-driven behavior, and modular design for home automation and IoT applications.
- Host: GitHub
- URL: https://github.com/arrajkamel/motiondetectionsecuritysystem
- Owner: ArrajKamel
- Created: 2025-01-09T22:59:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-03T19:23:16.000Z (over 1 year ago)
- Last Synced: 2025-03-25T14:29:42.578Z (over 1 year ago)
- Topics: arduino, cpp, infrared-sensor, motion-sensor
- Language: C++
- Homepage:
- Size: 729 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# π Motion Detection Security System
## π Overview
The **Motion Detection Security System** is an Arduino-based project designed to provide a robust and reliable security solution. It leverages a Sharp infrared sensor for motion detection, a 4x4 keypad for password authentication, and a Finite State Machine (FSM) to manage the system's behavior. The project is modular and scalable, making it suitable for real-world applications like home automation, and IoT security.
---
## π― Features
- **Motion Detection**: Utilizes the Sharp 2D120x infrared sensor to detect motion within a defined range.
- **Password Protection**: A 4x4 keypad is used to enter and verify passwords, ensuring secure access to critical states like sleep mode.
- **Finite State Machine (FSM)**: Clearly defined states (`IDLE`, `TIMER_ON`, `ALARM_ACTIV`, and `SLEEP`) for structured and predictable behavior.
- **Alarm System**: Activates a red LED and buzzer after a defined timeout period when motion is detected but not resolved.
- **Sleep Mode**: Disables motion detection and alarms, conserving energy until manually reactivated.
- **Energy Efficiency**: The system supports toggling to sleep mode, which disables unnecessary hardware until required.
---
## π§ Hardware Components
### Required Components
1. **Arduino Mega**
2. **Sharp 2D120x Infrared Distance Sensor**
3. **4x4 Keypad**
4. **16x2 LCD**
5. **Buzzer**
6. **Red LED**
7. **Push Button (Activation Toggle)**
### Hardware Connections
1. **Sharp Sensor**:
- Signal pin β `A15`
- VCC β `5v`
- Ground β `GND`
2. **4x4 Keypad**:
- Row pins β Digital pins `{A0, A1, A2, A3}`
- Column pins β Digital pins `{A4, A5, A7, A8}`
3. **LCD with I2C**:
- LCD shield is used.
5. **Buzzer and LED**:
- Buzzer pin β `25`
- LED pin β `26`
6. **Activation Button**:
- One side β `33`
- Ground β `GND`
## Schema

### note
- consider the Sharp Sensor instead of the Ultrasonic Distance Sensor.
---
## βοΈ System States
The system is governed by a Finite State Machine with the following states:
1. **IDLE**:
- The system scans for motion using the Sharp sensor.
- Transitions to `TIMER_ON` on motion detection or stays in `IDLE` if no motion is detected.
2. **TIMER_ON**:
- A timer is activated when motion is detected.
- The system transitions to `ALARM_ACTIV` on timeout, to `SLEEP` if the correct password is entered, or back to `IDLE` if motion ceases.
3. **ALARM_ACTIV**:
- The system activates a buzzer and LED.
- Transitions to `SLEEP` on correct password entry or to `IDLE` after the alarm auto-stops.
4. **SLEEP**:
- The system disables motion detection and alarms.
- Transitions back to `IDLE` upon pressing the activation button.
## π FSM Diagram

---
### π Real-World Applications
This project can be applied to various domains, such as:
1. **Home Security**: Detect motion and secure the premises with alarms and authentication.
2. **IoT Devices**: Integrate with smart home systems for advanced automation.
3. **Industrial Monitoring**: Use the system to monitor unauthorized access in factories or warehouses.
---
### π Future Improvements
1. **WiFi Integration**: Add ESP32 capabilities to send notifications to a mobile app or email.
2. **Battery Optimization**: Implement low-power modes for energy-efficient operation.
3. **Camera Integration**: Add a camera module for capturing images upon motion detection.
---
## π₯οΈ Software Implementation
### Libraries Used
1. `LiquidCrystal.h`: For interfacing with the LCD.
2. `Keypad.h`: For handling input from the 4x4 keypad.
### FSM Implementation
The FSM is implemented using an `enum` to define the states, with transitions handled in a `switch-case` structure. Each state has its own function to manage behavior and transitions.
### Key Functions
1. **Motion Detection**
```cpp
void checkMotion() {
int sharpValue = analogRead(SHARP_SENSOR_PIN);
motionDetected = (sharpValue > 300 && sharpValue < 700); // Adjust range
if (motionDetected) {
currentState = TIMER_ON;
timerStartTime = millis();
lcd.clear();
lcd.print("Motion Detected");
}
}
```
2. **Password Verification**
```cpp
void handleKeypadInput() {
char key = keypad.getKey();
if (key) {
enteredPassword += key;
lcd.setCursor(0, 1);
lcd.print(enteredPassword);
if (enteredPassword.length() == correctPassword.length()) {
if (enteredPassword == correctPassword) {
currentState = SLEEP;
enterSleepMode();
} else {
lcd.print("Wrong Password");
delay(2000);
enteredPassword = "";
}
}
}
}
```
3. **Sleep Mode Activation**
```cpp
void enterSleepMode() {
lcd.clear();
lcd.print("Entering Sleep");
delay(2000);
lcd.clear();
lcd.print("System in Sleep");
}
```
4. **Activation Button Handling**
```cpp
void handleActivationButton() {
if (digitalRead(ACTIVATION_BUTTON) == LOW) {
lcd.clear();
lcd.print("Reactivating...");
delay(5000); // Simulate delay
currentState = IDLE;
lcd.clear();
lcd.print("System Ready");
}
}
```
---
## π« Letβs Collaborate
Feel free to fork this repository or submit a pull request to improve or expand this project. Letβs build something great together!