WhatsApp Surveillance Video Camera with IR Proximity Sensor
As you can see in my previous electronics projects, I am fond of developing web applications showing good congruence with Twilio's API, giving unique features to electronics projects via WhatsApp.
In this project, I wanted to create a surveillance video camera for my library, especially for one particular bookcase, to get notified when someone takes a book or organizes books differently. In that regard, I programmed a Raspberry Pi 3 Model B+ to capture the first-look thumbnail image and record a video with timestamp according to the data collated by Arduino Nano - motion and brightness. After collecting files and information from sensors, Raspberry Pi transfers them to the file_pathway webhook to be sent to the verified phone number as WhatsApp notification messages. In PHP, I provided the source code of the file_pathway webhook: save the file_pathway webhook on your server by entering your Twilio account settings - works stupendously even on the localhost.
Aside from this project, if you need a host server for the file_pathway webhook or a user interface on your server to manage the uploaded files easily, inspect this web application on TheAmplituhedron.
Step 1: Twilio for WhatsApp
To send WhatsApp messages through Twilio's API, the only thing you need to do is to sign up for a Twilio Trial Account.
After signing up, with your SID and Auth Token, you can use Twilio's API for WhatsApp without any charge. As explained on Twilio, you need to join a shared phone number with your phone in order to verify your phone number and initiate WhatsApp template messages.
Important: In this project, we use Twilio's API to send WhatsApp notification messages in PHP and thus you do not need to change the default endpoint URL of your Twilio application in the Sandbox. In other words, you can use the file_pathway webhook even on the localhost.
For more information and learn how to activate your account, click the link below.
You can sign up for Twilio with my referral code here.
Step 2: Developing the file_pathway webhook
Elicit files and information from Raspberry Pi to save them to the server - video, captured thumbnail image, and brightness.
Send the currently uploaded files to the verified phone number as intrusion alert via WhatsApp.
To manage that, you have to download Twilio PHP Helper Library in your server from here.
- If the uploaded file names are not empty, get the brightness value and file properties for each uploaded file - name, temporary name, size, and extension.
- Check whether the uploaded file extensions are in allowed formats and whether the uploaded file sizes exceed the data limit - 5MB.
- Define media URLs.
- Upload files to the server.
- Send the information of the uploaded files, including temporary names, to Raspberry Pi as the response message.
- Define the required properties by Twilio's API to send files and information to the verified phone number via WhatsApp - SID, AUTH_TOKEN, Verified Number, and Shared Number.
- Note: Refrain from adding '+' at the beginning of the phone numbers when entering them as send_data_to_WhatsApp() function parameters.
Step 3: Setting Up Raspberry Pi
If you are a novice in programming with Raspberry Pi, you can find well-explained instructions and tutorials on the official Raspberry Pi website.
To go to the official Raspberry Pi setting up tutorial, click here.
- Update Raspberry Pi before running the terminal.
Step 4: Setting Up the Camera Module
To learn how to connect the Raspberry Pi Camera Module to your Raspberry Pi and take pictures, record video, and apply image effects, go to the official getting started with the camera module tutorial.
Step 5: Programming Raspberry Pi to send files and information to the file_pathway webhook in Python
- Create a file named whatsapp_surveillance.py on your IDE.
- Add the required libraries.
- Set up BCM GPIO numbering.
- Define input pins to get signals from Arduino Nano.
- Initiate the camera module with pre-defined settings.
- Annotate the date on the generated files as the timestamp.
- Capture an image as the thumbnail and record a 15 seconds video.
Note: Raspberry Pi records videos in the h264 format, but unfortunately, this format is not supported by WhatsApp. To convert video formats, download MP4Box as shown here.
- Convert the h264 format to the mp4 format using MP4Box as terminal command to open videos on WhatsApp.
- Define the file_pathway location to send the currently recorded video and data to the server. I used TheAmplituhedron to host the file_pathway webhook for my surveillance camera, change the URL as your file_pathway directory location on your server - e.g., https://www.theamplituhedron.com/dashboard/WhatsApp-Surveillance-Camera/file_pathway.php
- Define the files and the data parameters - video, captured image, and brightness.
Note: Download the requests library to make HTTP requests in Python as shown here.
- Make an HTTP Post Request to the file_pathway webhook to send information.
- Print the response sent by the file_pathway webhook.
- Initiate the loop.
- Get values from the input pins.
- If the proximity sensor detects motion, activate record_trespassing() and send_video_to_server() functions.
Code testing on the shell:
Display the generated files(.h264,.jpg,.mp4) on Raspberry Pi:
Step 6: Reading Analog Sensors with Raspberry Pi using Arduino Nano
Unfortunately, Raspberry Pi is not capable of reading analog signals from analog sensors since it does not include a built-in ADC (Analog to Digital Converter) circuit.
You can either add an external ADC such as the MCP3008 to read analog signals with Raspberry Pi or use capacitors to read resistance values.
Nevertheless, in this project, I used an Arduino Nano to read analog signals from the analog sensors because I have lots of spare Arduino Nano boards at my disposal. Arduino Nano generates digital output values according to the thresholds for each sensor - GP2Y0A02YK0F Infrared Proximity Sensor and Photoresistor. If the predefined condition is met, it produces 1 (HIGH) as the digital output detected as the input value by Raspberry Pi.
Then, Raspberry Pi can read analog signals from sensors as the digital output values generated by Arduino Nano with the input pins to activate record_trespassing() and send_video_to_server() functions.
Do not forget to add voltage dividers for each input pin due to the voltage discrepancy between Raspberry Pi and Arduino Nano.
- Get brightness as percentage values from the photoresistor using the map() function.
- Get distance in centimeters from the GP2Y0A02YK0F Infrared Proximity Sensor using the sensor value in the datasheet - 0.0048828125 (5 / 1024).
- Define conditions to generate digital output values as signals detectable by Raspberry Pi.
Features
1-) Check whether the brightness is optimum or low for the camera module using the photoresistor.
2-) Detect intruders using the GP2Y0A02YK0F Infrared Proximity Sensor.
3-) If the proximity sensor detects motion, capture a first-look thumbnail image and record a 15 seconds video.
4-) Send the captured image(jpg), the video(mp4), and the brightness value as intrusion alert to the verified phone number via WhatsApp.
Connections
Set up Raspberry Pi and its peripherals.
Assembly the camera module holder.
Attach Arduino Nano, sensors, and components on the breadboard.
Affix the camera module and the breadboard to the Raspberry Pi board case. And, connect the Raspberry Pi GPIO input pins to the Arduino Nano digital output pins as shown on the schematic.
Videos
Schematics
Code Files and Downloads
https://www.theamplituhedron.com/dashboard/WhatsApp-Surveillance-Camera/
WhatsApp Surveillance Video Camera with IR Proximity Sensor
- Comments(0)
- Likes(1)
- Kutluhan Aktar May 11,2021
- 1 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-
9design
-
10usability
-
9creativity
-
8content
More by Kutluhan Aktar
- Joker Remote Hazardous Gas Station and Monitor For a long time, I wanted to create a unique device to observe the presence of varying hazardous gas...
- Darth Vader IoT Cryptocurrency Tracker and Display w/ Raspberry Pi Pico Instead of using a mobile or web application, I decided to develop a brand-new device to track and d...
- Bluetooth Mobile Remote Lamp with Weather Station I have created an electronics project named Remote Lamp two years ago, as my new room lighting syste...
- Multi-Model AI-Based Mechanical Anomaly Detector w/ BLE Mechanical anomaly detection is critical in autonomous manufacturing processes so as to prevent equi...
- AI-assisted Pipeline Diagnostics and Inspection w/ mmWave StorySince the beginning of the industrial revolution, accurate pipeline system maintenance has been...
- IoT AI-driven Smart Grocery Cart w/ Edge Impulse Especially after the recent success of Amazon Go cashierless convenience stores, there is a surge in...
- BLE Mobile Star Wars Remote Lamp w/ Weather & Gas Station As you may have seen, I have created a similar remote Bluetooth-enabled lighting system for my room....
- IoT Bookmark and Reading (Book Ratings) Tracker w/ Qubitro While reading books or comics, I am fond of recording my ratings on a daily basis to track any surge...
- Iron Man Walkie-Talkie (Two-Way Radio) for Texting w/ LoRa For a long time, I have wanted to experiment with LoRa (short for long-range), which is a spread spe...
- Jigglypuff IoT Carbon Dioxide and Dust Monitor (Tracker) w/ Telegram The dust density and the carbon dioxide (CO2) density affect my sleep quality and health detrimental...
- IoT Heart Rate (BPM) Monitor and Tracker w/ Tuya Smart Heart rate, or pulse, is the number of times your heart beats each minute (BPM). While the heart cir...
- Raspberry Pi Adjustable Air Quality Detector Running on GUI I had been working on a project with which I could collate air quality information from an MQ-135 Ai...
- WhatsApp Coronavirus Notifier Bot Running on Raspberry Pi First of all, I hope that you and your loved ones are safe and healthy during these unprecedented ti...
- WhatsApp Surveillance Video Camera with IR Proximity Sensor As you can see in my previous electronics projects, I am fond of developing web applications showing...
- Marvel and DC Weekly New Comics Release List Tracker I am a huge comic book fan and collect issues of my favorite titles every week. Therefore, I check w...
- Arduino-Based (ATmega32U4) Mouse and Keyboard Controller For a long time, I needed a simple device allowing me to send varying mouse and keyboard commands to...
- Bluetooth-enabled Snowman Weather and Air Quality Gift Card Although it is struggling for me to create a brand-new design while paying homage to the classic Chr...
- WhatsApp Halloween-Themed RFID Talking Doorbell w/ RGB Eyes Despite the fact that making a hilarious yet not deceitful joke with a jack-o'-lantern on Halloween ...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
123 0 0 -
DIY Laser Power Meter with Arduino
172 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
162 0 2 -