DIY Home Security System With Motion Detection and Remote Door Lock

by zmn_10 in Circuits > Microcontrollers

114 Views, 4 Favorites, 0 Comments

DIY Home Security System With Motion Detection and Remote Door Lock

1C12337E-5939-40C5-9B96-585F68B04A70.JPEG
IMG_1927.jpeg

In this project, we'll create a comprehensive home security system using a Raspberry Pi with a camera module for motion detection and an Arduino Nano IoT33 to control a door lock system. The system is integrated with a real-time Google Firebase database and a web app developed with React JS for user control and monitoring.

System Overview

  • Motion Detection Subsystem: Uses Raspberry Pi and MotionEyeOS for motion detection. When motion is detected, an email notification is sent.
  • Door Lock Subsystem: Uses Arduino Nano IoT33, a servo motor for the lock mechanism, and a buzzer for alerts. The status of the door lock is stored in a Firebase Real-Time Database.
  • Web App: Developed using React JS, this allows users to monitor the camera feed, and control the door lock and buzzer remotely.


Supplies

OIP.eKpWzVyWFZnuxcBhzw2oYwHaHa.jpeg
51Mkzk6grML._AC_SL1500_.jpg
camera_v2.jpg
QKTIBQSFPO12162020223253_buzzer-komponent-cin-416-26-B.png
Servo-Motor-30Kg-02.png
1*c1vv7b34H8WdvqeD_SBxgw.jpg
arduino-nano-33-iot.jpg
Breadboard.jpg
original.jpg

Components Needed

  1. Raspberry Pi (any model with internet capability)
  2. Raspberry Pi Camera Module
  3. Arduino Nano IoT33
  4. Servo Motor
  5. Buzzer (Optional)
  6. Breadboard and Jumper Wires
  7. Micro USB Cables
  8. Access to a Firebase Account
  9. Computer for development (with Node.js installed for React JS)

Install MotionEyeOS on Raspberry Pi

  • Download the MotionEyeOS image for your Raspberry Pi model.

https://github.com/motioneyeproject/motioneyeos

  • Write the image to your SD card using Etcher/Raspberry Pi Imager.

https://www.raspberrypi.com/software/

  • Insert the SD card into the Raspberry Pi and power it on.

Configure MotionEyeOS

  • Connect to the Raspberry Pi via its IP address in a web browser.
  • Configure the camera settings and enable motion detection.
  • Set up email notifications under the Motion Notifications section.

Connect Raspberry Pi Camera Module

  • Connect the camera module to the Raspberry Pi using the camera port.
  • Test the camera in the MotionEyeOS interface.

Connecting All Components Together, Arduino

Screenshot 2024-05-24 at 6.56.54 pm.png

Servo Motor Pin : D3

Buzzer : D8 (Optional)

Setting Up Firebase Real-Time Database

Create a Firebase Project:

  • Go to the Firebase Console and create a new project.
  • Enable the Firebase Realtime Database.

Configure Database Rules:

  • Set up rules to allow read and write access during development.

{

 "rules": {

   ".read": true,

   ".write": true

  }

}


Add Database Structure:

  • Create a structure to store the door lock status and buzzer status.

Create a web app inside your firebase project:

  • Copy the firebaseConfig-> we need it for react app

Building the Door Lock System With Arduino Nano IoT33

Wiring the Components:

  • Connect the servo motor to the PWM pin on the Arduino.
  • Connect the buzzer to a digital pin on the Arduino e.g. Digital Pin 3.
  • Use the breadboard to organize your connections.

Arduino Code for Door Lock:

  • Use the Arduino IDE to program the Nano IoT33.
  • Implement code to control the servo motor and buzzer.
  • Connect the Arduino to your Firebase Real-Time Database using Wi-Fi.

Required Libraries:

  • WiFiNINA.h
  • Servo.h
  • Firebase_Arduino_WiFiNINA.h
  • ArduinoJson.h

Requirements:

  • Your Firebase Database URL
  • Your Firebase Database Secret Key
  • Go to your project setting -> choose Service Accounts -> Choose Database secrets and generate a new private key and copy that
  • Your wifi credentials -> Name and Password
  • String path for database object:
  • e.g. "/door/status"
  • door: {

status: "LOCKED"

}

Arduino Code for Door Lock system:

https://github.com/zmn17/Home-Smart-Security.git

Create Web App With ReactJS

  1. Set up the React Environment: (I used ViteJs) for setting up ReactJS app
  • Install NodeJS and NPM and Create a new React App using Vite.js
  • npm create vite@latest
  • enter the name of your project
  • choose React template
  • choose JavaScript for the language
  • Change the Directory the newly created app
  • cd 'your-project-name'
  • npm install
  • npm run dev - to start the development
  • Install firebase SDK for the react app
  • npm install firebase
  • Copy your firebaseConfig from Google Firebase in your project setting - you will need it in react app when developing and connecting the app to database


  • Here is the code for react app:
  • https://github.com/zmn17/Home-Smart-Security.git


Conclusion

FMNKO3SLWJ9JRDE.jpg

This DIY project showcases the integration of a Raspberry Pi, Arduino Nano IoT33, Firebase, and a React JS web app to create a robust home security system. By following the steps outlined, you can customize and expand the system to meet your specific needs and ensure the safety of your home.

Submitted to Deakin University, School of IT, Unit SIT210/730 - Embedded Systems Development