Good day, habrovchane! After several experiments with the development of a video surveillance system, which I reflected in a previous
publication , I decided to share the final decision.

Description of the final decision
After analyzing my experience of using the video surveillance system and recommendations for the previous post (special thanks to
Varkus ), as a result I chose an implementation using a PIR sensor (hereinafter
referred to as the sensor) for determining movements / movements. Algorithm solutions implemented in Python.
Earlier, I did not want to use an additional hardware component in my decision, but the approach using the sensor turned out to be very simple and concise. Moreover, the sensor turned out to be inexpensive if ordered on aliexpress.
')
Hardware
From the "iron" used:
- Raspberry Pi3;
- Logitech USB camera;
- motion sensor SR501P1.
To work at night, you must additionally purchase an infrared emitter (lamp).
The sensor is connected using 30-centimeter connectors, I give the appearance below.

Yes, I pre-selected the required sensitivity by adjusting it with a potentiometer.
Software part
To automate the process of video surveillance limited to one Python-script that does all the work, namely, monitors the movement using the sensor and, if it is revealed:
- takes several pictures of the room, using the Python OpenCV library for this;
- saves images in Yandex.Disk;
- upon reaching a certain threshold of movements, in my case - ten identified movements, stops shooting and sends the last of the saved images to Telegram.
The threshold is set in order to limit the number of shots when fixing movements. Upon reaching the threshold, the shooting is stopped and one of the last saved photos is sent to Telegram. I set the threshold equal to ten, this is enough to fix the fact of penetration in the photo. Video writing is considered superfluous, besides the photo takes up less space.
In the final version, I refused to use the algorithm for determining the faces in the photo.
The script code, without the algorithm by definition of persons, is given below.
from gpiozero import MotionSensor import cv2 import telepot import time def Telegram_send(input_file): import glob import os file=max(glob.iglob(input_file+'*.jpg'),key=os.path.getctime) bot = telepot.Bot('*************************************') bot.sendMessage(*********, 'Motion detected!') bot.sendPhoto(*********, open(file,'rb')) def main(): file='/home/pi/alarms/' counter=1 threshold=10 time.sleep(10) pir=MotionSensor(4) try: camera=cv2.VideoCapture(0) while counter<=threshold:
Pros and cons of using a sensor
Advantages of using the sensor:
1. A simple final code in the form of a ONE Python script that implements the entire algorithm of work.
2. The relative cheapness of the sensor.
Of the minuses I see so far only the possibility of failure of the sensor during its long operation. But, perhaps, this device (sensor) will be stable and work for a long time, despite the fact that this is not an “industrial” version.
Additional features
I also tried to connect a second camera. Raspberry coped with the processing of video from two cameras without problems.
Conclusion
Using the sensor turned out to be quite simple. It remains to test the solution for long-term use.
I hope that the proposed option will be a useful alternative to the implementation of a video surveillance system, which can be easily done with your own hands.