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.
import RPi.GPIO as GPIO import time from picamera import PiCamera from time import sleep import datetime camera = PiCamera() camera.rotation = 180 GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) #I use Board pin numbering instead of Broadcom(BCM) GPIO.setup(7, GPIO.IN) #Read output from sensor while True: i=GPIO.input(7) if i == 1: #sensor output - High print ("Movement Detected") date = datetime.datetime.now().strftime("%d-%m-%Y_%H:%M:%S") camera.capture('/home/pi/Desktop/'+date+'.jpg') time.sleep(2) date = datetime.datetime.now().strftime("%d-%m-%Y_%H:%M:%S") camera.capture('/home/pi/Desktop/'+date+'.jpg') time.sleep(2) date = datetime.datetime.now().strftime("%d-%m-%Y_%H:%M:%S") camera.capture('/home/pi/Desktop/'+date+'.jpg') time.sleep(10)
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 : https://www.raspberrypi.org/documentation/configuration/external-storage.md
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.