Smart Home Security Camera
This post explains the technical background of the security camera system, shown in the following movie. The post will answer the questions: How to detect a thief, how to take a photo, how to get notifications on your phone, and whether the system would work in reality.
How to Detect a Thief?
In order to detect a thief I made use of an acceleration sensor that I placed at the apartment’s door. The sensor listens for significant changes in the measured x-acceleration. This technique was so precise, that even the slightest knock triggered the motion detection.
bool motionDetected(float tolerance) { readMPU6050SensorData(&mpu6050Data, MPU_addr); int16_t accX = mpu6050Data.acceleration.x; return (accX > boundaries.max + delta * tolerance || accX < boundaries.min - delta * tolerance); }
Because the door is at the opposite side of the room it was required to transfer the information (whether a motion was detected) to a Raspberry Pi’s camera. I made use of a 433 Mhz transmitter and receiver system with two Teensy microcontrollers respectively.
In a nutshell: When a thief enters the room, the acceleration sensor will recognize that. It will transmit that information to another microcontroller that itself forwards the signal to the Raspberry Pi (via a serial USB connection).
Getting the information from the receiver-microcontroller to the Raspberry Pi was not as easy as I initially thought. I am explaining the installation of the required npm package in the post Install Node SerialPort on Raspberry Pi.
Since I have to enter the room through the same door I needed to check whether it was a guest or me who came in. Recognizing the acceleration profile of the person who opens the door and analyzing it with a self improving machine learning algorithm until it works after I’ve generated 10.000 training samples? Easier: Assigning a static IP address to my smartphone and sending a ping request every time motion was detected. If the phone responds there was no doubt that it was me who came in. Or at least that my phone was within range of the WiFi router.
How to Take Photos?
The primary component of the system is the security camera: After a thief has been detected, a Node.js script on the Raspberry Pi takes a photo and stores it locally. The npm package raspicam makes that part pretty easy.
I’m using the Rapberry Pi camera module but a USB webcam would do the job just as well.
How to Get Notifications on Your Phone?
In the video you saw that I was notified about my dad stealing a bottle of wine while I was hanging out in Karlsruhe’s park. In order to achieve that the Raspberry Pi functions as a Telegram bot. So what’s that? Telegram is an open-source messenger with an amazing API. Among other things you can create bots (Telegram users that are not actual person but a computer). In the past I published a post about another bot that I wrote.
For the notification I created a bot called “Smart Home” that is in my Telegram contact list. Now the Raspberry Pi is the computer behind that bot and sends a photo right into the normal Telegram chat so that I can see it on my phone if I have an internet connection.
The node-telegram-bot-api package simplifies the API for Node.js applications.
Would it Actually Work?
If someone was seriously trying to enter my room without permission, would it work? I had a comparable situation when the apartment lessors announced, the annual inspection of the fire detection systems of each apartment would be conducted next week. I was not at home so the system was armed and ready to detect the technician.
And indeed: A few hours after I left the apartment, a bunch of photos came in, showing the brave technician doing his job (photo 2). On the way out it looks like he saw the acceleration sensor at the door and inspected it briefly (photo 4). The following photos proof the operability: