hello everybody! i'm beginner in raspberry pi world.
want make data logger in mysql humidity , temp sensor on pir motions detections.
using hc-sr501 pir sensor , am2302 temperature & humidity sensor.
code pir sensor start working
question is, how can log temp , humidity value records in mysql on pir motion detections?
want make data logger in mysql humidity , temp sensor on pir motions detections.
using hc-sr501 pir sensor , am2302 temperature & humidity sensor.
code pir sensor start working
code: select all
#!/usr/bin/python #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ #|r|a|s|p|b|e|r|r|y|p|i|-|s|p|y|.|c|o|.|u|k| #+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # # pir_1.py # detect movement using pir module # # author : matt hawkins # date : 21/01/2013 # import required python libraries import rpi.gpio gpio import time # use bcm gpio references # instead of physical pin numbers gpio.setmode(gpio.bcm) # define gpio use on pi gpio_pir = 7 print "pir module test (ctrl-c exit)" # set pin input gpio.setup(gpio_pir,gpio.in) # echo current_state = 0 previous_state = 0 try: print "waiting pir settle ..." # loop until pir output 0 while gpio.input(gpio_pir)==1: current_state = 0 print " ready" # loop until users quits ctrl-c while true : # read pir state current_state = gpio.input(gpio_pir) if current_state==1 , previous_state==0: # pir triggered print " motion detected!" # record previous state previous_state=1 elif current_state==0 , previous_state==1: # pir has returned ready state print " ready" previous_state=0 # wait 10 milliseconds time.sleep(0.01) except keyboardinterrupt: print " quit" # reset gpio settings gpio.cleanup()
raspberrypi
Comments
Post a Comment