This is Qiita's first post. Thank you.
I wanted to make an inexpensive monitoring system with Raspberry Pi and sensors. Specifically, it is a monitoring system that installs RaspBerryPi Zero, RaspBerryPi camera, and motion sensor (HC-SR501) in the laboratory, takes a picture with a camera when a person is detected, and sends the image to Slack (unfinished).
・ Raspberry Pi zero ・ Raspberry Pi camera ・ HC-SR501 Human body infrared sensitive module ・ 3 jumper wires (female / female)
If the motion sensor detects a person, the program to shoot with the Raspberry Pi camera is as follows.
monitoring.py
import time
import picamera
import RPi.GPIO as GPIO
INTERVAL = 5
SLEEPTIME = 1
GPIO_PIN = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIO_PIN,GPIO.IN)
if __name__ == '__main__':
try:
print("CTRL to cancel processing+C")
while True:
if(GPIO.input(GPIO_PIN) == GPIO.HIGH):
with picamera.PiCamera() as camera
camera.resolution = (1024,768)
camera.brightness = 70
camera.capture('picture.jpg')
else:
time.sleep(INTERVAL)
except KeyboardInterrupt:
print("All processing finished")
finally:
GPIO.cleanup()
I built a local web server and confirmed that the images were acquired.
Currently, this system is incomplete because the process of sending data to Slack has not been implemented. After implementation, I would like to pursue the usefulness of this system by comparing it with other monitoring systems.
Recommended Posts