Python

code to activate PIR and LED

1 2638
deks  
Hi,
I have a code which works fine for motion dedection but I would like to lighten a LED if a motion is dedected. So I suppose I have to add some additional e.g. GPIO_LED = 27 to lighten the LED. Thanks for help.

Python-code:
  1. # Import required Python libraries
  2. import RPi.GPIO as GPIO
  3. import time

  4. # Use BCM GPIO references
  5. # instead of physical pin numbers
  6. GPIO.setmode(GPIO.BCM)

  7. # Define GPIO to use on Pi
  8. GPIO_PIR = 17

  9. print "PIR Module Test (CTRL-C to exit)"

  10. # Set pin as input
  11. GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo

  12. Current_State  = 0
  13. Previous_State = 0

  14. try:

  15.   print "Waiting for PIR to settle ..."

  16.   # Loop until PIR output is 0
  17.   while GPIO.input(GPIO_PIR)==1:
  18.     Current_State  = 0

  19.   print "  Ready"

  20.   # Loop until users quits with CTRL-C
  21.   while True :

  22.     # Read PIR state
  23.     Current_State = GPIO.input(GPIO_PIR)

  24.     if Current_State==1 and Previous_State==0:
  25.       # PIR is triggered
  26.       print "  Motion detected!"
  27.       # Record previous state
  28.       Previous_State=1
  29.     elif Current_State==0 and Previous_State==1:
  30.       # PIR has returned to ready state
  31.       print "  Ready"
  32.       Previous_State=0

  33.     # Wait for 10 milliseconds
  34.     time.sleep(0.01)

  35. except KeyboardInterrupt:
  36.   print "  Quit"
  37.   # Reset GPIO settings
  38.   GPIO.cleanup()
Copy the Code
hisunaj  
The code is mentioned which is used for the activation of the program. The initial success of the program is connected with essay lab for the customers. The margin is followed for the patterns for the individuals. Code is codified by the programmers.

You have to log in before you can reply Login | Sign Up

Points Rules