Meet SpiCam, my Raspberry Pi project, and the story behind it.

A Raspberry Pi based, Spy Camera, with Motion Detection, Android Notifications, Intruder Alerts, Snapshots, E-Mails and Daily Timelapse Video.

Note: If you are interested only in the technical aspect and not in the story behind it I suggest you skip to the 2nd part of this article.

The Story.

About a month back, something abnormal happened at our home.

It was 12:30 pm, and me, my sister and our house maid were the only ones present in the house. I left for college at around 2:00 pm. Soon after I left, my sister and our maid also left, leaving no one at the house.

I returned from college at exactly 5:04 pm (Yep, just went for the practical attendance), and I remember this because I switched on mobile screen to connect to WiFi and an image which was queued to send got sent on a WhatsApp group. I tossed my bag on the living room sofa and went directly in the bedroom to change, and lie down. I did not notice anything abnormal until my sister came home about 15 minutes after me and called me outside to ask me about what had happened.

I went to the living room and was shocked. We have a sofa which has a cloth covering, so stains remain for quite a long time on it. I saw that the left side of the sofa was completely wet from the water kept in a decorative vessel kept just above the sofa. What’s truly shocking was that, there were 4 towels lying around the area, one inside the vessel, completely soaked in water, one outside the vessel but not on the sofa, and the other 2 towels spread out open on the sofa, just as if they were deliberately kept there to soak water. We don’t even have 4 towels in our living room two of the towels were from the bedroom.

The vessel in which we found the towels.

Now, the only inference that I can derive from it that someone accidentally tipped off the vessel and tried to clean it up, but it was not me or my sister. Also as I earlier stated that stains (even water) stay for quite a long time on our sofa, so I checked out the stain marks and they were spread up to the edge of the sofa — about 2 feet from the point of contact of water. So I figured that this happened a while ago, at least 45 minutes ago(when no one was home).

My sister left before the maid so our obvious action was to call her and ask her about it, and we did. But she replied that “I specifically remember everything being normal because I set aside the books and laptop kept on the sofa right before leaving”. We trust her with our main door key, so you can say that we trust her enough to know she is telling the truth. That crosses everyone that was home that afternoon.

The only people with main door key access are my parents, me, my sister, our neighbor family, and the maid. My parents were at work, and our neighbors wouldn’t have any reason to enter our home, drop off a vessel, try to clean it up and not tell us about it. We live a co-operative housing complex with decent facilities but no CCTV cameras, so there was no way for me to find out who exactly came in at that time. I called up the security guard present at that time and asked if anyone came to our house between 2:30 pm and 5 pm and to my surprise, he said that a delivery guy had come at 4 pm. We did not have anything scheduled for delivery that afternoon, nor there was any note or envelope at door. He also did not leave any message or parcel with the security guard as well. This is when we started to panic and I called up my Dad to tell him about this, he told me that he would check if any valuable was missing from the lockers when he returns. At least nothing was visibly missing from any of the rooms. My dad came home and checked every locker for anything missing, but NOTHING was.

This is when I felt the need of a CCTV camera, so I decided to make one of my own!


SpiCam as you must have guessed from the title, is a Spy Camera based on the Raspberry Pi.

Raspberry Pi with Camera Module attached to it.

Something about Raspberry Pi.

Raspberry Pi is as their official website mentions, a credit card-sized computer that plugs into your TV and a keyboard. It is a capable little computer which can be used in electronics projects, and for many of the things that your desktop PC does, like spreadsheets, word processing, browsing the internet, and playing games.


SpiCam, unlike normal CCTV cameras, does not keep on recording all the static footage eating up space, and only starts recording when motion is detected.

It sets up a live stream of the footage, which is accessible from anywhere via the internet. So I can see what SpiCam is seeing from my mobile phone while sitting in my classroom, too.


Whenever motion is detected it notifies me on my mobile phone, and starts recording the footage, at the same time it also captures images.

Video recording
Image Captured

Once it has detected that the motion has stopped it, emails me the entire video footage of the event and out of the images it detects which frame has the most movement and emails me only that image.

Emails Sent to me via Raspberry Pi.

It also takes a snapshot every 10 seconds regardless of whether motion is detected, and compiles all the snaps into a fast-forwarded video time-lapse 1 minute long and emails me the time-lapse daily at, 3:00 am.

Many more features can be added like SMS alerts for when I don’t have internet access etc.

For Geeks


SpiCam is constantly connected to the internet and the on-board camera.

It captures frames at about 30fps, when SpiCam captures two frames it converts each image into a data matrix, by using Python functions (details on the technical part ahead). It subtracts the latter one from the former and detects the number of pixels that have changed.

If the number of pixels have changed by more than a set threshold value, it considers it as a motion frame. Note that it is running at 30fps, so you would have 30 such conflicts for a second’s motion. So, I have set it to detect atleast 60 such frames before declaring it as motion, this prevents smalls motions like dust particles, light change, shadow movement etc to be removed.

When a motion is detected it triggers 1 python script to send me a notification on my phone via an app called Pushetta, and also starts recording video footage as well as saves the frames used for calculation in a buffer.

Notification Via Pushetta

‘No motion’ detection is also a similar process but I have set it to read 300 frames of no motion before calling off the event.

When the event is complete, it detects the frame with most number of changed pixels and saves it from the buffer, 2 python scripts are triggered as well, one for emailing me the captured image, one for emailing me the captured video, when the video and image have been successfully mailed to me, it automatically deletes them to save space on the machine (only 1.7gb of free storage space).

Then, I have set a script which emails me the timelapse video of the previous day, to run at 3 am everyday.


I’m using this OpenCV based script for motion detection and video recording, also a Raspberry Pi service called motion, which is also based on OpenCV.

To make the camera live stream accessible from the internet, I needed to port forward the port raspberry pi was streaming on. I used port 8081(default).

All the code used is available on my GitHub repo

If you want to make a Spy Camera of your own follow the steps in the description. Make sure you follow all the steps only cloning the repo will not work.

I have setup all the files to suit my needs, you are free to edit any python file to suit your needs. Especially, I recommend going through the motion.conf file, it’s quite long but everything is documented well.