Last active
January 11, 2019 15:14
-
-
Save starbuck93/46553d7d194b94c7020d2589d97a66be to your computer and use it in GitHub Desktop.
DoorLaser -- using a garage door laser beam to detect people walking through a doorway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#borrowed from https://www.hackster.io/hardikrathod/pir-motion-sensor-with-raspberry-pi-415c04 | |
#and https://raspberrypihq.com/use-a-push-button-with-raspberry-pi-gpio/ | |
import RPi.GPIO as GPIO | |
import time | |
#import sys | |
#from influxdb import InfluxDBClient | |
import requests | |
import automationhat | |
# Set this variables, influxDB should be localhost on Pi | |
host = "localhost" | |
port = 8086 | |
#user = "root" | |
#password = "root" | |
# The database we created | |
dbname = "laser" | |
#sample period | |
interval = 0.05 | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP) #laser | |
curr_time = 0 | |
prev_time = 0 | |
count = 0 | |
print("Starting program", time.time(), "GPIO 15RX:", GPIO.input(15)) | |
try: | |
while True: | |
if GPIO.input(15): | |
curr_time = time.time() | |
print("Laser Broken!", time.time(), "Diff:", curr_time - prev_time, "Count:", count) | |
if curr_time - prev_time > 0.15 and count > 1: | |
data = 'laserdoor value=1' | |
print(requests.post('http://localhost:8086/write?db=laser', data=data)) | |
count = 0 | |
elif curr_time - prev_time <= 0.15: | |
count = count + 1 | |
else: | |
count = 0 | |
prev_time=curr_time | |
time.sleep(interval) | |
except: | |
GPIO.cleanup() | |
print("\nBye, bye!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment