Build your own security camera system: A step-by-step guide | Viam
Build your own security camera system: A step-by-step guide
Create a DIY security camera with a Raspberry Pi, featuring customizable triggers and actions using Viam's modular capabilities.
Date: August 12, 2024
Author: Matt Vella
Introduction
Create a DIY security camera system that allows for highly customizable detections, triggers, and actions without coding for each scenario.
I have a basic security camera that I don’t use. Solutions like Ring and Blink lack the features I need, and I dislike the idea of live video streaming to the cloud and paying additional monthly fees.
So, as an engineer, I did what I do best: I designed a security camera solution tailored specifically to my own needs. And you can too!
Whether you’re looking to build your own security camera system that notifies you when a UPS delivery arrives, automatically lets your kids in when the camera recognizes their faces, or alerts you when children are unattended in a pool area, this Raspberry Pi security project is for you.
In this step-by-step guide, you’ll learn how to:
- Determine your DIY security camera's goals
- Gather the hardware for your DIY security camera
- Install viam-server to connect your DIY security camera
- Add capabilities to your DIY security camera
- Add triggers for your DIY security camera
- Build a mobile app to monitor your DIY security camera
- Plan to enhance your DIY security camera
Now, let’s get building!
Step 1: Determine your DIY security camera's goals
Before you begin your build, stop and think, "What would make a security camera useful for me?" And get specific!
Whether it's monitoring package deliveries at your front door, keeping an eye on your backyard, or ensuring 24/7 surveillance of your garage, this clarity will guide your project and ensure that your efforts align with your needs.
If you're unsure how specific to get, check out my list—it's a bit unusual, but here it is:
My requirements when building my own security camera:
- Protecting our ducks: We have egg-laying backyard ducks that have been attacked by bears and foxes at night. I’d like to set up a camera specifically aimed at their coop to detect and alert me when any wildlife comes within a certain distance.
- Monitoring our dog Luna: Our dog, Luna, is a “southern girl” hailing from Tennessee and, after 5 years, still dislikes being outside in the cold northern winters. I’d love a camera by the back door that alerts us when Luna is waiting to come inside before she gets too cold.
- Detering Boo, the neighbor’s cat: Our neighbor’s big, bad Maine Coon cat, Boo, loves to come to our porch to taunt our indoor cat. If a camera could detect Boo’s presence on our porch and trigger a deterrent, that would be nice.
You're unlikely to have the same security camera needs as I do, but I'd bet your list isn't fully covered by standard motion and person detection features on today's cameras.
Step 2: Gather the hardware for your DIY security project
For this project, you’ll need:
- Any computer that can run viam-server
- Any camera that can run on viam-server
- Raspberry Pi
- Mobile device (not a requirement)
Choose the right camera type
When selecting a camera, make sure it has specific features that ensure it operates correctly in different environments. Select a security camera that’s waterproof, has night vision, and has a two-way speaker system.
For this tutorial, we’ll be using an inexpensive RTSP IP camera.
Choose the best Raspberry Pi for your security camera
For this project, we’ll be using a Raspberry Pi 5. Our team found it has twice the performance of a Raspberry Pi 4, making it the perfect choice for a project featuring object detection.
Step 3: Install viam-server to connect your DIY security camera
To start setting up your project:
- Install viam-server on the computer of your choice.
- Head over to the Viam App, name your new machine (whatever you’d like), and add a new machine instance.
Step 4: Add capabilities to your DIY security camera
Capabilities fall into two categories:
- Core to the project (like the camera).
- Contextual to our use cases (like the specific ML models you want to use).
These can be added to or changed over time without writing new code.
Add the camera to your Raspberry Pi security project
One camera is essential to the project, but we could add any number of cameras.
If you are using a webcam, like the one on your laptop, this is as simple as:
- Choosing the model ‘webcam.’
- Selecting the camera from the component dropdown.
- Saving your configuration.
If you are using another type of camera, configuration is the same process, though you would choose a different model and might need to add some other attributes.
I configured my RTSP camera using these instructions found in our documentation.
Add machine learning (ML) models to your Raspberry Pi security project
Deploy your own ML model to your Raspberry Pi security project
With Viam, you can easily upload your custom ML models to the Viam Registry for use on your smart devices. Our platform supports TensorFlow Lite, TensorFlow, PyTorch, and ONNX frameworks.
To upload your model, follow these step-by-step instructions.
Train your own ML model
You can also use Viam to train your own custom ML model on images captured by your smart machine. Our platform allows for the training of Single Label Classification Models, Multi-Label Classification Models, or Object Detection Models.
To train your own ML model, follow these step-by-step instructions.
Use a pre-trained ML model for your Raspberry Pi security project
For my project’s purposes — detecting wildlife and pets around my premises — I decided to use some pre-trained ML models to work alongside Viam’s computer vision service.
Just as you can import your own ML models into the app, you can also add others from repositories like HuggingFace, Model Zoo, or Kaggle.
To upload your model, follow these step-by-step instructions.
With this, I was able to add models for:
A Mobilenet wildlife detector trained on hundreds of thousands of wild animal images.
An Efficientnet detector trained on the popular COCO dataset.
Both of these models can be found on the Viam Registry and can be configured on your DIY security camera system in just a few clicks.
Step 5: Add triggers for your DIY security camera
Configure the event manager and customize solutions
With our camera, ML models, and vision service in place, you're ready to start using them.
To get started, create highly customized solutions tailored to your specific use case using any of the Viam SDKs.
In this case, I wanted to create a solution that could:
- Monitor for configured "events" to trigger.
- Act on configured notifications when events are triggered.
The README describes how to configure rules and notifications. Here’s the configuration I used for a specific scenario:
{
"mode": "home",
"events": [
{
"name": "Poor Luna got left outside",
"modes": ["home", "away"],
"debounce_interval_secs": 300,
"rule_logic_type": "AND",
"notifications": [
{
"type": "sms",
"carrier": "att",
"phone": "9175550100"
}
],
"rules": [
{
"type": "detection",
"detector": "coco-detector",
"confidence_pct": 0.7,
"class_regex": "dog",
"cameras": ["backdoor-camera"]
}
]
}
]
}
Step 6: Build a mobile app to monitor your DIY security camera
Leveraging ML with my camera to get notifications is great, and it took me less than a day to set up.
But I also wanted:
- The ability to view and manage triggered event video replays.
- An intuitive interface to create and modify rules and notifications.
How can I turn my smartphone into a security camera?
I knew there was a Viam Flutter SDK, which enables you to build applications for mobile, web, and desktop, so I decided to challenge myself.
I developed a mobile app called SAVCAM (Smart AI Viam Camera).
Like any security camera app, you can view a live feed from any of your cameras, and you can see notifications and video replays of events. But unlike any security camera app I’ve seen, this Viam-based camera offers much more flexibility in terms of what it's looking for and how it reacts.
To build your own Flutter application that integrates with Viam, see the full instructions.
Step 7: Plan to enhance your DIY security camera
I have more ideas for taking my system further, especially around other types of notifications:
- I’ve added IFTTT support to trigger actions based on detecting a car or person.
- To deter wild animals, I might use an ESP32 with Viam’s micro-RDK to activate erratic buzzers and LEDs when they are detected.
The possibilities are endless—consider what other enhancements or integrations could make your DIY security camera system even more effective and tailored to your needs.
Start building your own security camera
We've covered the essentials of creating a highly customizable DIY security camera system, from gathering the necessary hardware to installing viam-server and adding advanced capabilities and triggers.
Ready to build your own DIY security camera? Sign up for our free app, explore its many features, and join our community to get direct support from our engineers.