Last active
August 29, 2015 14:03
-
-
Save LuisFDuarte/42a2ebb6ae36125b68cc to your computer and use it in GitHub Desktop.
This code runs on a Raspberry Pi device, with a motion sensor connected to it.
This file contains 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
import RPi.GPIO as GPIO ##GPIO library | |
from ubidots import ApiClient ##Ubidots Library | |
import time ##time library for delays | |
GPIO.setmode(GPIO.BCM)##set up BCM as numbering system for inputs | |
GPIO.setup(7,GPIO.IN)##Declaring GPIO7 as input for the sensor | |
try: | |
api=ApiClient("75617caf2933588b7fd0da531155d16035138535")##put your own apikey | |
people= api.get_variable("53b9f8ff76254274effbbace")##put your own variable's id | |
except: | |
print "cant connect"##if this happens check your internet conection | |
while(1): | |
presence=GPIO.input(7)#)# saving the value of the sensor | |
if(presence==0):##if presence is zero that means the other car is still there :( | |
people.save_value({'value':presence})##sending value to ubidots | |
time.sleep(1)##check every 5 seconds if the other car moves | |
print "cero" | |
if(presence): | |
people.save_value({'value':presence})##the other car left so is empty now :) | |
time.sleep(1) | |
print "uno" | |
GPIO.cleanup()##reset the status of the GPIO pins | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment