[CIrcuit1][1]By default PIR input pin(middle) is HIGH. When i run the below code, gp.input(27) always gives me value 1.

My code:

import RPi.GPIO as gp
import time
gp.setup(2, gp.OUT)
gp.setup(27, gp.IN)
print "LED is ON"
gp.output(2, gp.HIGH)
i = gp.input(27)
print i

while True:
                  if gp.input(27):
                                      print "motion detected"
                                      gp.output(2, gp.LOW)
                           print "No motion detected"

OutPut: LED is ON 1 motion detected

Kindly let me know if i have done any mistake in code. Plz find the circuit i have used in attachment.

  • There is no attachment – Human Feb 22 '17 at 6:49
  • While waiting for the missing circuit attachment, I'm wondering if you have a pin 27 pulled to ground by a resistor (e.g., a 10K one). – Dave W. Smith Feb 22 '17 at 6:53
  • Most PIR devices send pulses (one or more) and don't leave the line low for long. You might need to use wait_for_edge instead. Plus they are fairly susceptible to EM interference, so careful if you have wifi plugged in... – BJ Black Feb 22 '17 at 13:08
  • Hi , Can you explain me bit clear about wait_for_edge concept – kish Feb 28 '17 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.