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.
- 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, andSLEEP) 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.
- Arduino Mega
- Sharp 2D120x Infrared Distance Sensor
- 4x4 Keypad
- 16x2 LCD
- Buzzer
- Red LED
- Push Button (Activation Toggle)
-
Sharp Sensor:
- Signal pin →
A15 - VCC →
5v - Ground →
GND
- Signal pin →
-
4x4 Keypad:
- Row pins → Digital pins
{A0, A1, A2, A3} - Column pins → Digital pins
{A4, A5, A7, A8}
- Row pins → Digital pins
-
LCD with I2C:
- LCD shield is used.
-
Buzzer and LED:
- Buzzer pin →
25 - LED pin →
26
- Buzzer pin →
-
Activation Button:
- One side →
33 - Ground →
GND
- One side →
- consider the Sharp Sensor instead of the Ultrasonic Distance Sensor.
The system is governed by a Finite State Machine with the following states:
-
IDLE:
- The system scans for motion using the Sharp sensor.
- Transitions to
TIMER_ONon motion detection or stays inIDLEif no motion is detected.
-
TIMER_ON:
- A timer is activated when motion is detected.
- The system transitions to
ALARM_ACTIVon timeout, toSLEEPif the correct password is entered, or back toIDLEif motion ceases.
-
ALARM_ACTIV:
- The system activates a buzzer and LED.
- Transitions to
SLEEPon correct password entry or toIDLEafter the alarm auto-stops.
-
SLEEP:
- The system disables motion detection and alarms.
- Transitions back to
IDLEupon pressing the activation button.
This project can be applied to various domains, such as:
- Home Security: Detect motion and secure the premises with alarms and authentication.
- IoT Devices: Integrate with smart home systems for advanced automation.
- Industrial Monitoring: Use the system to monitor unauthorized access in factories or warehouses.
- WiFi Integration: Add ESP32 capabilities to send notifications to a mobile app or email.
- Battery Optimization: Implement low-power modes for energy-efficient operation.
- Camera Integration: Add a camera module for capturing images upon motion detection.
LiquidCrystal.h: For interfacing with the LCD.Keypad.h: For handling input from the 4x4 keypad.
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.
- Motion Detection
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"); } }- Password Verification
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 = ""; } } } }- Sleep Mode Activation
void enterSleepMode() { lcd.clear(); lcd.print("Entering Sleep"); delay(2000); lcd.clear(); lcd.print("System in Sleep"); }- Activation Button Handling
void handleActivationButton() { if (digitalRead(ACTIVATION_BUTTON) == LOW) { lcd.clear(); lcd.print("Reactivating..."); delay(5000); // Simulate delay currentState = IDLE; lcd.clear(); lcd.print("System Ready"); } }Feel free to fork this repository or submit a pull request to improve or expand this project. Let’s build something great together!

