0

This question already has an answer here:

I was trying to get my PIR sensor working but I got really strange readings. I unplugged everything from the breadboard, including the motion sensor but I still got a signal to the GPIO pin. After some testing I realized that whenever I have a cable connected to that pin (cobbler or single) I constantly get random signals.

This is my code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

PIR_PIN = 25

GPIO.setup(PIR_PIN, GPIO.IN)

print "start"

try:
       while True:
                if GPIO.input(PIR_PIN):
                        print "Motion"
                else:
                        print "No"
                time.sleep(0.5)
except KeyboardInterrupt:
       print "Quit"
       GPIO.cleanup()

I get "no" a few seconds, then I get "Motion" a few seconds and so on. But if I disconnect the cable from the Pi there's only "No" readouts.

I've tried changing pin but there's not change. I also tried setting the wifi dongle on a extension cable to get it away from the Pi but that didn't help either.

Isn't this super basic stuff?

marked as duplicate by goldilocks Nov 7 '15 at 22:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

When the PIR is attached to the GPIO there should not be random signals. If there are random signals your wiring or components are faulty.

When nothing is connected to the GPIO to force it high or low it will float randomly showing low or high. That is why you use a weak pull-up or pull-down to force the GPIO high or low in the absence of a stronger signal (from your sensor).

Add a pull-up if your sensor gives 0 for an alarm. Use a pull-down if your sensor gives 1 for an alarm. You can enable the internal pull-ups/downs in software. Check your library docementation.

Not the answer you're looking for? Browse other questions tagged or ask your own question.