
[ad_1]
Due to global growth across various sectors, more people are moving away from their places of residence or of work. There is the need of safeguarding their home/compounds/factories/neighbourhoods and this is where the Intrusion detection using various techniques is gaining popularity. Internet of Things has further revolutionized such applications in the present days by means of alternatives wherein the user can receive updates on intrusion as and when desired through seamless connectivity from any desired location. The proposed system is a Raspberry Pi security system using Pi camera and a Passive InfraRed (PIR) sensor as a motion detector unit. The images so obtained are stored in Firebase storage.
Any compound (indoors/outdoors) or zone can be put under observation and even a very slight movement by any human/animal/heat radiating body can be very effectively sensed by a PIR thereby triggering the Pi cam to capture an image of the observation zone. It can be modified to be used as a burglar detector, to capture wildlife photos, Intruder detection, Face recognition or various such applications.
Without Firebase settings enabled, the captured images are by default saved in Raspberry Pi. Either ways, the autogenerated name itself contains the time and date of entry thereby giving the added advantage for user verification of the zone of observation (and verification of the same against expected/unexpected trespassing) by checking the folder. The same can be accessed on the Firebase system on your Android/iOS device or via web App. Our proposed setup shows a web App setting and its implementation.

We are using Python language for programming. Before coding, the user needs to configure Raspbian OS on Raspberry Pi. When we are using Raspberry Pi, we need to install Pi camera library files to run this project in Raspberry Pi. Refer Figure 1 and Figure 2.
Figure 1 represents the author’s proposed set up of the observation zone and the R-Pi assembly along with the Pi camera.
Figure 2 represents the Author’s proposed set up of the observation zone and the R-Pi assembly along with the Pi camera under Intrusion and the same is being detected. Image is captured and stored for reference.

movement activates the Pi camera and initiates it to record the image at that instant.
Installations and set up:
To use a Raspberry Pi camera (connected with a ribbon cable), first enable the camera interface in Raspberry Pi config setting.The following code is used for this part-
• $ sudo apt-get install python-picamera
• $ sudo apt-get installpython3-picamera- Find below the step by step instructions for implementation
Step 1: We have to enable Raspberry Pi camera software before we can use the camera module. In the desktop environment, first go to the main Menu Select Preferences > Raspberry Pi Configuration. Select the Interfaces tab and Enable the camera.
Step 2: After successfully completing step 1 on Raspberry Pi, it is recommended to perform software update. It can be done by running the following Linux commands in the Linux • • Terminal –
• $ sudo apt-get update
• $ sudo apt-get upgrade- Step 3:Once the update and upgrade are done, we need to reboot the system.
- Step 4: After reboot we have to write the code in Python3 /ThonnyIDE for working of project.
Figure 3 provides the basic block diagram of the proposed setup.

Testing (for the Pi camera using motion sensor):
- In testing first, we have to test the code of the Pi camera in terminal, and it will be run
for 5 seconds. This ensures that motion is detected. - raspistill -o test.jpg.

Table 1 shows the bill of materials
| Components | Quantity | Description |
| Raspberry Pi 3b+ | 1 | For Programming |
| PIR Sensor | 1 | Motion Sensor |
| Pi cam | 1 | Pi Camera with 5 MP |
| Jumper Wire | 3 | Female-Female jumper |
| Connections Between PIR Sensor and A Raspberry Pi | ||
| Board Label | Pin Function (PIR) | Raspberry Pi |
| GND | Ground | GND |
| 5V | 5V Power Input | 5V |
| OUT | Output of the sensor | Pin 7 (GPIO 4) |
As we all know that the memory storage requirement of each clicked image is large. Hence, we propose storing these in Firebase, which is a set of hosting services for any type of application. It offers NoSQL, real-time hosting of databases, content, social authentication, and notifications, or services, such as a real-time communication server.
Following are the step wise instruction for any New User
1] Open the website
A Firebase project is a container for your Apple, Android, and Web apps. Apps in this project will share features like Database, User Management and Remote Configuration.
A Firebase project is a Cloud project. When you create a new Firebase project in the Firebase console, you’re actually creating a Google Cloud project behind the scenes.
2] Click on the button Get Started
3] This will lead us to the Project console https://console.firebase.google.com/
4] Click on the button Create a Project
5] Create a project (Step 1 of 3)
Give a name to our project.
My project name is Intrusion Detection.
Accept the terms of Firebase and press the button Continue.
6] Google Analytics (Step 2 of 3)
Google Analytics is a free and unlimited analytics solution that enables targeting, reporting, and more in Firebase Crashlytics, Cloud Messaging, In-App Messaging, Remote Configuration, A/B Testing, and Cloud Functions.
It is recommended to activate the Enable Google Analytics for this Project.
Press the button Continue.
7] Configure Google Analytics (Step 3 of 3)
Enter Analytics location. This represents the country/region of your organization. This does not affect where Google may process and store Customer Data for Firebase.
Data sharing settings: I didn’t opt for the default settings for sharing Google Analytics Data.
Accept the Google Analytics terms.
Move on to the button Create a Project.
8] Your new project is ready. Press the button Continue.
Your project name should be visible on the screen to you now.
The sidebar provides various choices related to your project.
Select Build
Select Storage
Select the button Get Started.
For the steps 1-8, refer fig 4 to see the screenshots of individual vital steps in implementation.

9] I preferred to start in production mode.
Press the button Next.
Enter Cloud Storage Location. [After you set this location, you cannot change it later. This location setting will also be the default location for Cloud Firestore.]
I selected Asia South1.
This will lead to creating a default bucket.
10] In Storage, go to Rules, Select Edit Rules
We need read and write access in all possible conditions, so in the program on the right hand side window, we have to delete “: if false”
Click on the button Publish.
11] Go to Build.
Select Real Time Database.
Click on the button Create Database.
We have to opt for Start in test mode. Your data is open by default to enable quick setup. However, you must update your security rules within 30 days to enable long-term client read/write access. This is to ensure Third Party Allowance.
Click on the button Enable.
This should provide you a link to your project database. For example, the link for my project.
12] Go to Project Overview.
This will Add an app to get started.
You will have a choice to select from Android, iOS and Web App. [we opted for Web App]
To ensure a web-based access to our project details, select the button Web.
13] Register App.
Enter the name of Project Intrusion Detection in the space to enter App Nickname.
Select the button Register App.
14] Go to the button Add Firebase SDK.
Select the button Use npm [https://www.npmjs.com/]
We now need Authentication details in terms of JS SDK, that is
Your web app’s Firebase configuration (must include the following details)
apiKey:
authDomain:
databaseURL:
projectId:
storageBucket:
messagingSenderId:
appId:
measurementId:
Remember these details are unique to you and be careful about sharing them to anyone.
For Firebase JS SDK v7.20.0 and later, measurementId is optional.
These details are to be included in the R Pi program for authentication and further processing.
Click the button Continue to Console.
Figure 5 covers the remaining steps in terms of screenshot support for installation.

So far, if all the steps have been processed in a correct manner, we should now be ready to obtain all PIR sensed and Firebase routed clicked images as shown in the figure 6. In case needed, you do have a choice of uploading some files (previously captured images).

Figure 6: Author’s Firebase storage portal of the observation zone with a Pi camera
Code: (all blanks to be filled by your own unique IDs as generated in step 14)
Code: (all blanks to be filled by your own unique IDs as generated in step 14)
import RPi.GPIO as GPIO
import time
from datetime import datetime
from picamera import PiCamera
from time import sleep
import os
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
PIR_PIN = 7
#camera.rotation = 180
GPIO.setup(PIR_PIN, GPIO.IN)
import pyrebase
firebaseConfig = {
'apiKey': __________________________,
'authDomain': "____________________________”,
'databaseURL': "______________________________",
'projectId': "_____________",
'storageBucket': "________________",
'messagingSenderId': "__________________",
'appId': "___________________________",
'measurementId': "_______________"
}
firebase = pyrebase.initialize_app(firebaseConfig)
storage = firebase.storage()
camera = PiCamera()
while True:
try:
if GPIO.input(PIR_PIN) == GPIO.HIGH:
print("Motion detected!")
now = datetime.now()
dt = now.strftime("%d%m%Y%H:%M:%S")
name = dt+".jpg"
camera.capture(name)
print(name+" saved")
storage.child(name).put(name)
print("Image sent")
os.remove(name)
print("File Removed")
sleep(2)
except:
camera.close()[ad_2]
Source link


