From 36e27ddd134ee387e6b1c2768900508d66ed06da Mon Sep 17 00:00:00 2001 From: Jordan-Fielding <107819004+Jordan-Fielding@users.noreply.github.com> Date: Mon, 4 Jul 2022 15:27:39 +1000 Subject: [PATCH] First Script --- .idea/.gitignore | 8 ++++++++ .idea/BugMotion.iml | 11 +++++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ main.py | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/BugMotion.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 main.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/BugMotion.iml b/.idea/BugMotion.iml new file mode 100644 index 0000000..2cdb1e3 --- /dev/null +++ b/.idea/BugMotion.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..963bd34 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..610ded5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..75218c8 --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +import RPi.GPIO as GPIO +import time +from picamera import PiCamera + +camera = PiCamera() +GPIO.setwarnings(False) +GPIO.setmode(GPIO.BOARD) +GPIO.setup(22, GPIO.IN) #Read output from PIR motion sensor +GPIO.setup(27, GPIO.OUT) #LED output pin + +i=GPIO.input(22) +try: + time.sleep(2) # to stabilize sensor + while True: + ts = time.time() + st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S') + if i==0: #When output from motion sensor is LOW + print ("No bugs detected",i) + GPIO.output(3, 0) #Turn OFF LED + time.sleep(0.1) + if i==1: #When output from motion sensor is HIGH + print ("bugs detected",i) + GPIO.output(3, 1) #Turn ON LED + camera.capture('image_Time_{}.jpg'.format(st)) + os.system('libcamera-jpeg -o /home/pi/Pictures/image_Time_{}.jpg'.format(st)) + camera.close() #Capture an Image + time.sleep(0.1) + +except: + GPIO.cleanup() + + + + +