Raspberry Pi Security Infrared Camera (Python Edition)

Infrared security camera installed in my home It is a memorandum when it was created. (The content of the initial introduction is quite different from the current one)

[Things to use]

Raspberry Pi 2 Model B: Amazon 5,562 yen Infrared camera NoIR Camera Board 790-2811: Amazon 4,590 yen Pyroelectric motion sensor: Akizuki Denshi 400 yen Red LED (3mm): Akizuki Denshi 10 yen Carbon resistance (220kΩ): Sengoku Densho 16 yen

[Prerequisites]

・ "RPi.GPIO" has been introduced ・ Camera is already connected to the CSI camera port -The camera must be enabled in "raspi-config" -The VCC and GND terminals of the pyroelectric motion sensor have already been connected. The OUT terminal is connected to any GPIO (No. 5 is used here) ・ LED for sensor detection confirmation is connected (Here, connect to port 6 with a resistor in between)

[Camera operation check: command]

Still image $ raspistill -o test.jpg   ** Video ** $ raspivid -o test.h264

[Python camera control environment]

$ sudo apt-get update $ sudo apt-get install python-picamera

[Still image test of Python alone]

StillTest.py


# coding: utf-8

import picamera
import time
 
camera = picamera.PiCamera()

camera.led = True
camera.start_preview()
time.sleep(3)

camera.capture('test.jpg')

camera.stop_preview()
camera.led = False

camera.close()

[Video test of Python alone]

MovieTest.py


# coding: utf-8

import picamera
import time

camera = picamera.PiCamera()

camera.led = True
camera.start_preview()

camera.start_recording('test.h264')
camera.wait_recording(5)
camera.stop_recording()

camera.stop_preview()
camera.led = False

camera.close()

[Sensor test of Python alone]

SensorTest.py


# coding: utf-8

import RPi.GPIO as GPIO
import time

SLEEP_TIME = 1
INTAVAL_TIME = 1

GPIO.cleanup()
GPIO.setmode(GPIO.BCM)

SENSOR = 5
GPIO.setup(SENSOR, GPIO.IN)

LED = 6
GPIO.setup(LED, GPIO.OUT) 

intaval = time.time() - INTAVAL_TIME

while True:
#	print GPIO.input(SENSOR)
	GPIO.output(LED, GPIO.LOW)

	if( GPIO.input(SENSOR) == GPIO.HIGH ) and ( intaval + INTAVAL_TIME < time.time() ):
		intaval = time.time()
#		print "!! Detection !!"
		GPIO.output(LED, GPIO.HIGH)

	time.sleep(SLEEP_TIME)

[Python sensor & camera cooperation test (still image)]

StillSensorTest.py


# coding: utf-8

import datetime

import picamera
import time

import RPi.GPIO as GPIO
import time

SLEEP_TIME = 1
INTAVAL_TIME = 1

GPIO.cleanup()
GPIO.setmode(GPIO.BCM)

SENSOR = 5
GPIO.setup(SENSOR, GPIO.IN)

LED = 6
GPIO.setup(LED, GPIO.OUT) 

intaval = time.time() - INTAVAL_TIME

camera = picamera.PiCamera()

while True:
	if( GPIO.input(SENSOR) == GPIO.HIGH ) and ( intaval + INTAVAL_TIME < time.time() ):
		intaval = time.time()

		GPIO.output(LED, GPIO.HIGH)

		camera.led = True
		camera.start_preview()
		time.sleep(1)

		NowTime = datetime.datetime.now()
		camera.capture(NowTime.strftime("%Y%m%d_%H:%M:%S") + '.jpg')

		camera.stop_preview()
		camera.led = False

		GPIO.output(LED, GPIO.LOW)

	time.sleep(SLEEP_TIME)

[Remaining memorandum]

・ Sensor detection time stamp (Python → MySQL) -Store the image save destination in the date folder (Python → File) ・ Camera control from PHP, refer to DB & image, execute Python  (PHP → DB or Python or Command or File) ・ Control and reference from the outside with a smartphone app (JavaScript → PHP)

https://github.com/Naoki-Takamatsu/Raspberry-Pi_Test

Recommended Posts

Raspberry Pi Security Infrared Camera (Python Edition)
Raspberry Pi video camera
How to use Raspberry Pi pie camera Python
I tried L-Chika with Raspberry Pi 4 (Python edition)
Thermal Camera (Thermo AI Device TiD) Raspberry Pi Edition
Raspberry Pi + Python + OpenGL memo
raspberry pi 1 model b, python
Display USB camera video with Python OpenCV with Raspberry Pi
Python beginner opens and closes interlocking camera with Raspberry Pi
[Raspberry Pi] Changed Python default to Python3
Hello World with Raspberry Pi + Minecraft Pi Edition
Adafruit Python BluefruitLE works on Raspberry Pi.
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Working with GPS on Raspberry Pi 3 Python
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Discord bot with python raspberry pi zero with [Notes]
Detect slide switches using python on Raspberry Pi 3!
[Amateur remarks] Raspberry Pi 3, Wordpress vs Raspberry Pi 3, python, Django
Detect magnet switches using python on Raspberry Pi 3!
Raspberry Pi backup
Get CPU information of Raspberry Pi with Python
Make DHT11 available on Raspberry Pi + python (memo)
Sound the buzzer using python on Raspberry Pi 3!
Serial communication between Raspberry pi --Arduino Uno (Python)
Connect to MySQL with Python on Raspberry Pi
Build a Python development environment on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
Measure CPU temperature of Raspberry Pi with Python
From setting up Raspberry Pi to installing Python environment
Create a color sensor using a Raspberry Pi and a camera
Display images taken with the Raspberry Pi camera module
How to use the Raspberry Pi relay module Python
Try debugging Python on Raspberry Pi with Visual Studio.
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
USB boot with Raspberry Pi 4 Model B (3) LVM edition
Face detection from images taken with Raspberry Pi camera
Thermal Camera (Thermo AI Device TiD) Python OpenCV Edition
Install pyenv on Raspberry Pi and version control Python
Output to "7-segment LED" using python on Raspberry Pi 3!
Thermal camera (thermo AI device TiD) Python VL53L0X edition
A memorandum when making a surveillance camera with Raspberry Pi
Let's operate GPIO of Raspberry Pi with Python CGI
Raspberry Pi with Elixir, which is cooler than Python
Thermal Camera (Thermo AI Device TiD) Python D6T-44L-06 Edition
A * algorithm (Python edition)
First Python 3rd Edition
What is Raspberry Pi?
GPGPU with Raspberry Pi
pigpio on Raspberry pi
Python --Simple security software
Raspberry Pi Bad Knowledge
Let's do Raspberry Pi?
Python, OpenCV camera capture
DigitalSignage with Raspberry Pi
Raspberry Pi 4 setup memo
Cython on Raspberry Pi
Raspberry Pi system monitoring
VScode intellisense doesn't work on Raspberry Pi OS 64bit! (Python)
Update Python for Raspberry Pi to 3.7 or later with pyenv
Run AWS IoT Device SDK for Python on Raspberry Pi