0

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?

1 Answers1

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.

joan
  • 71,024
  • 5
  • 73
  • 106