A Raspberry Pi-based motion detection and surveillance system that supports email transfer of recordings.
Based on Picamera2 beta.
Works with the camera module V2 and Debian "bullseye".
Check out how to configure the camera before continuing: how to configure the camera modules
- Motion detection
- Email notifications with video attachments
- Customizable motion sensitivity
- Camera zoom control
- Bandwidth limitation
- Optional local recording deletion after email transfer
sudo apt-get install -y python3-picamera2
python3 main.py
To start the motion detector on boot, follow these steps:
[Desktop Entry]
Name=Motion Detector
Type=Application
Comment=RPI motion detection
Exec=sh -c 'sleep 10 && /usr/bin/python3 /path/to/motion_detector.py arguments... > /path/to/logfile 2>&1'
Shows a preview window of what the camera sees.
python3 main.py --preview
Example of a x2 zoom:
python3 main.py --zoom 0.5
If you want the motion detection to be more or less sensitive, you can adjust it as follows:
The lower, the more sensitive.
python3 main.py --min-pixel-diff 5.2
Sends videos to a specified email.
python3 main.py --email-username USERNAME --email-password PASSWORD --recipient TO_EMAIL
Deletes the local video after sending them to the recipient email.
python3 main.py --delete-local-recordings
If you run your Raspberry Pi in your home network, you might want to limit the bandwidth. If you don't have a router with QoS, you can use tools like WonderShaper.
Follow these steps to enable traffic shaping on boot:
- Install WonderShaper
sudo apt-get install wondershaper
- Create the file
sudo nano /etc/systemd/system/wondershaper.service
- Add the content
Here is an example systemd unit file that limits the upload and download speed of the "wlan0" interface to 2048 Kbps:
[Unit]
Description=Limit UL and DL to 2048kbps
[Service]
Type=simple
ExecStart=wondershaper wlan0 2048 2048
[Install]
WantedBy=multi-user.target
- Start the service
sudo systemctl enable --now wondershaper.service