This project is for CPC357 Assignment. This intruder alarm system will trigger the buzzer and LED whenever the PIR motion sensor detected motion or the door sensor detect the door opens. On top of that, it will send the sensor data to GCP via MQTT and store the data into MongoDB Atlas Cloud Database. We can visualize the detection result in MongoDB Atlas using dashboard.
- Shaun Liew Xin Hong 154746
- Liew Hui Lek 151496
- Maker Feather AIoT S3 board
- Buzzer
- LED
- PIR Motion Sensor
- MC-38 Door Magnetic Sensor Switch
- Arduino Code
- Google Cloud Platform
- MongoDB Atlas
The intruder alarm system utilizes a passive infrared (PIR) motion sensor and MC-38 door magnetic sensor switch that are interfaced with the Maker Feather AIoT S3 board to detect intrusions.
When the PIR sensor senses movement or the door sensor detects an opening, it sends the data to the Maker Feather AIoT S3 board. The board will then activate the buzzer, which sounds an alarm and blinks the LED as a visual alert signal.
To communicate with the cloud, the Maker Feather AIoT S3 uses the MQTT protocol to publish the intrusion event data to the Google Cloud Platform. Google Cloud enables the collection of intrusion event data and stores it in a MongoDB NoSQL cloud database for long-term storage. Then, MongoDB Atlas will access the intrusion events data from the MongoDB cloud database to visualise the stored intrusion events data using the Atlas dashboard.
Setup the Hardware as shown in the image below.
- Create a Google Cloud VM
- SSH into the VM and run the code below to install MQTT.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
sudo apt-get install mosquito-clients
- Create a firewall rule to allow traffic on port 1883.
- Add the firewall rule to the VM instance's configuration.
- Edit the default-allow-internal rule to allow ingress traffic on TCP port 1883.
Download the intruder_detection.ino
and put into your Arduino IDE and change the Pin
, MQTT Server
, Wifi
setup accordingly.
Run the code as shown as below. Make sure your device is connected to your computer to upload the code.
In order to persist the sensor data sent from the device, we need to store it into MongoDB Atlas database instead of localhost.
-
Create a MongoDB Atlas Account
- make sure you use the same email as your GCP account.
-
Create a MongoDB Atlas Cluster as shown as below.
- After the cluster is created succesfully, get the connection string by clicking the connect button on the home page as shown below. Make sure you change the connection string
<password>
to your own password.
uri = "mongodb+srv:/shaunliew:<password>@intruder-detection.nvz8nim.mongodb.net/?retryWrites=true&w=majority"
-
go to the
gcp_ingest_data_mongo.py
and change the mongoDB Atlasurl connection string
andmqtt_broker_address
accordingly. -
SSH to the virtual machine created in GCP and copy the
gcp_ingest_data_mongo.py
and paste it into the VM using nano command. After you nano into the python file, copy paste the script pressctrl+X
to save it.
nano gcp_ingest_data_mongo.py
- Install the python libraries needed in your VM using the command below.
sudo apt install python3-pip
pip install paho-mqtt
sudo apt-get install -y mongodb
pip install pymongo
- Run the data ingestion python script.
python3 gcp_ingest_data_mongo.py
- Play around with your sensor so that it can send the data to the MongoDB as shown below.
Now you have successfully ingest the sensor data into MongoDB. You can check your detection result in your MongoDB Atlas Charts Dashboard
. You can create different pattern of graph according to your preferences.
You may view the final result from the youtube link below.