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)
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
・ "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)
Still image $ raspistill -o test.jpg ** Video ** $ raspivid -o test.h264
$ sudo apt-get update $ sudo apt-get install python-picamera
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()
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()
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)
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)
・ 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