Building a Secure and Customizable Raspberry Pi Security Camera: A Comprehensive Guide
Aug 22, 2024

Using a Raspberry Pi for a security camera offers several advantages making it an affordable surveillance solution for home or small business.
The Raspberry Pi is cost-effective, allowing you to build a fully functional security system without the high price tag associated with commercial options DVR/NVR systems. Its flexibility and customizability mean you can tailor the setup to your specific needs, whether you want to use multiple cameras, integrate motion detection, or connect it to other smart home devices. Additionally, the wide range of software options, such as MotionEyeOS or the `motion` software on Raspberry Pi OS, allows for easy setup and management, giving you control over features like streaming, recording, and alerts.
We can choose to store video footage locally on an SD card, external hard drive, or network-attached storage (NAS), ensuring that your data remains under your control. Also, we can integrate cloud storage solutions like Google Drive, Dropbox, or custom servers for remote access and backup.
Implementation Raspberry Pi Security Camera

Components
● Raspberry Pi (any model with a camera interface, e.g., Raspberry Pi 3, 4 or Zero W)
https://github.com/motioneye-project/motioneyeos/wiki/Supported-Devices
● Raspberry Pi Camera Module v2.1 (or a USB webcam)
● MicroSD Card (with at least 16GB storage, pre-installed with MotionEyeOS)
● External USB Hard Drive (with a least 500GB for video storage)
● High Quality Power Supply 5v
Steps to Set Up the Raspberry Pi Security Camera
1. Install Raspberry Pi Imager to a computer with an SD card reader. Put the SD card that you will use with your Raspberry Pi into the reader and launch Raspberry Pi Imager.
2. Select the Raspberry Pi 4 as Device
3. Choose OS and select Use Custom. Browse the MotionEyesOS image and flash the Raspberry Pi 4

4. Complete your custom setting (WiFi Setttings)
5. Put SD Card in Raspberry PI and power on.
MotionEye on Raspberry Pi
This is an online interface of the software motion, a video surveillance application with motion sensor.

Features
● Easy and friendly user interface for internet verses, mobile and tablets.
● It supports most USB cameras and also is compatible with Raspberry PI camera modules.
● Here we find support for IP cameras (network).
● Camera detection with alerts via email and functional days.
● For still images using the JPEG format and for videos using AVI format.
● Timelapse movies
● It worked with your local Area Network through the use of ethernet cables or through wireless connections.
● File storing to the device ‘s local SD card, USB drive or SMB share of the local network
● Sharing of videos and pictures on social platforms (Facebook, Instagram), storing of files in cloud services such as Google drive and Dropbox.
● By default, media files are accessible in the local network as SMB shares.
● Media files can also be managed with the help of FTP server which is already installed in PIM, or SFTP server
Installation
1.Install Python dependencies
sudo apt install python3-dev libcurl4-openssl-dev libssl-dev
2.Install PIP Python Manager
sudo apt install python3-pip
3.Download MotionEYE
sudo pip3 install 'https://github.com/motioneye-project/motioneye/archive/dev.tar.gz' --break-system-packages
4.Init installation script
sudo motioneye_init
5.Install libcamera package
sudo apt install libcamera-v4l2
6.Open a web browser on any device in the network and Access
http://raspberry_pi_IP:8765 Login: admin Password: (empty)

Configuration
1.Add a Camera

Select "Local V4L2 Camera" if you are using the Raspberry Pi Camera Module or a USB webcam. Configure the camera settings as needed.

2.Set Up Motion Detection
Go to the Motion Detection tab:

Enable motion detection and configure the sensitivity, detection zones, and other preferences.
3.Configure Storage
Go to the File Storage tab.

Set up the directory where we want to store recorded videos and images.
We ou can also configure cloud storage options like Google Drive or Dropbox.

4.Secure MotionEye
The default port is 8765 used by MotionEye for its web interface. If this port is accessible from the internet without proper security measures (like HTTPS and strong passwords), our camera system could be vulnerable.
● Setting up a VPN allows you to access the Raspberry Pi remotely without exposing ports directly to the internet. This is one of the most secure methods for remote access.
● Change the admin password by going to General Settings > User Accounts.

● Consider changing the default ports used by MotionEye to non-standard ones, making it harder for potential attackers to find our service.
Alternative Installation - MotionEyesOS
MotionEyeOS is a Linux distribution that allows one to convert the single board computer into a surveillance system.
1.Download and install Raspberry Pi Imager to a computer with an SD card reader. Put the SD card that you will use with your Raspberry Pi into the reader and launch Raspberry Pi Imager.
2.Download the last stable versión (v.20200606) of MotionEyesOS https://github.com/motioneye-project/motioneyeos/releases
3.Select the Raspberry Pi Device.
4.Choose a Use Custom image and flash your Raspberry Pi.

5.Put SD Card in Raspberry PI and power on.
6.Continue with previous Configuration
Additional Configurations
Set up notifications via email or webhooks. Configure the system to send alerts when motion is detected.

Troubleshooting
Cannot Access the MotionEye Web Interface
We can't reach the MotionEye web interface at http://raspberry_pi_IP:8765.
1.Run the following command to see if the service is running:
sudo systemctl status motioneye
If it's not running, try restarting it:
sudo systemctl restart motioneye
2.If you have a firewall enabled, ensure that port 8765 is open:
sudo ufw allow 8765/tcp
Camera Not Detected or No Video Feed
1.Ensure that the camera module or USB webcam is properly connected.
For the Raspberry Pi Camera Module, double-check the ribbon cable is seated correctly in the CSI slot.
2.Test the Camera:
Use the raspistill command to take a test photo:
raspistill -o test.jpg
If this doesn’t work, the camera may not be properly connected or could be faulty.
3.Verify Camera Interface is Enabled:
Ensure the camera interface is enabled in raspi-config:
sudo raspi-config
Go to Interfacing Options > Camera and make sure it's enabled.
Low Performance or High CPU Usage
Reducing the camera resolution or frame rate can significantly reduce CPU usage. Adjust these settings in the MotionEye interface under Video Device.
Storage Issues (e.g., Not Enough Space or Cannot Save Videos)
Configure MotionEye to automatically delete old files after a certain period or when storage space is low.
Go to Videos Section and set the Movies Lifetime, example: 15 days

Official MotionEye Documentation: https://github.com/motioneye-project/motioneye