Using Raspberry Pi camera (NOIR) and Python to build a home surveillance camera – Part 2 of 4 – Using PIR motion sensor and using external usb Flash drive as storage for surveillance data

This post is about using Raspberry Pi and HC-SR505 PIR sensor to record surveillance images and videos.The 1st script uses the SD card as a storage and the 2nd script uses external USB thumb drive as a storage option.

The Python script will take 3 pictures, 2 seconds apart and pause for 10 seconds when the PIR sensor detects a movement. There is an issue with false triggering with the HC-SR505 sensor. Initially I plan to use a more expensive Panasonic PIR sensor but due the the extra cost , I have decided to use the power of Python and OpenCV to write a motion dection script. All this will be in this post, below.

Board numbering (center 2 columns of numbers) and BCM numbering

import RPi.GPIO as GPIO
import time
from picamera import PiCamera
from time import sleep
import datetime

camera = PiCamera()
camera.rotation = 180

GPIO.setmode(GPIO.BOARD)       #I use Board pin numbering instead of Broadcom(BCM)
GPIO.setup(7, GPIO.IN)         #Read output from sensor
while True:
    if i == 1:               #sensor output - High
        print ("Movement Detected")
        date ="%d-%m-%Y_%H:%M:%S")
        date ="%d-%m-%Y_%H:%M:%S")
        date ="%d-%m-%Y_%H:%M:%S")

Use USB flash drive as a external storage for Pi model 3B+:

The steps that I took to mount a 64GB usb flash drive can be found in this link :

I just want to point out that initially my flash drive is formatted in FAT file system, but found out that using FAT with Pi (linux) is quite challenging and I am unable to write to drive. I re-format the usb drive to NTFS and it was a breeze. Hence I strongly recommend to format the usb drive to NTFS file system before plugging in into your Pi.

Exploring the usb mounted drive, when I right clicked, I was unable to ‘Move to Trash Bin’ . An error ‘Unable to find or create trash directory’ popped up. This might be because the Trash bin is own by root directory. After a few attempts to change owner and not being successful, I found out from here that by pressing ‘Shift’ + ‘Delete’ on the keyboard, it will bypass the Trash Bin process ie. the deleted files will be deleted forever and will not be in the Trash Bin at desktop. For me this is fine. I just have to ensure that the file(s) selected are really meant to be deleted. Untill I find the solution, this is what I will use.