2
\$\begingroup\$

I posted this on the Raspberry Pi StackExchange but I feel as though it might be better suited for here, as the SE is pretty inactive anyway.

I've got a fairly simple circuit that I've made where a motion detector is connected to a Raspberry Pi B+ GPIO by way of a fairly long ~30ft stretch of wire. The detector is being powered by a 9V battery and the schematic is as follows:

PIL Schematic

I'm running a python script to pick up the motion and it is as follows:

import RPi.GPIO as gpio
import time
gpio.setmode(gpio.BCM)
gpio.setup(17, gpio.IN)
while True:
  print ("LOW","HIGH")[gpio.input(17)]
  time.sleep(.5)

I was getting an output that was consistently 9-11 HIGHs, then 9-11 LOWs then repeating, and I was wondering what was up so I disconnected the PIR motion detector, leaving the wire not connected to anything, and I got the same result: a consistent fluctuation between low and high.

From my research, LOW for GPIO is roughly <0.54V while HIGH is >2V. Measuring the difference in voltage between the wire and the Raspberry Pi GND pin (PIN 39) gives me 0.32V consistently, with no fluctuation. Why is this happening, and how can I fix it?

\$\endgroup\$
4
  • \$\begingroup\$ Have you tried not using the cable? Your sensor may not be able to drive the capacitive load that the 30ft of cable introduces. Try bringing the sensor much closer and see how it behaves. \$\endgroup\$
    – sherrellbc
    Commented Apr 11, 2015 at 0:39
  • \$\begingroup\$ @sherrellbc It works fine when it is connected directly. The distance of the wire cannot be decreased, and I would prefer to have it wired instead of sending a wireless signal. Any ideas how to get around this? \$\endgroup\$
    – globby
    Commented Apr 11, 2015 at 0:43
  • 1
    \$\begingroup\$ If this is indeed the problem then you will need an additional line driver for this to work. Although, it may just be that the wire is showing its non-ideal antenna characteristics and picking up EMI. In this case, you could try using a shielded cable. Even still, I can't imagine your PIR sensor having much drive capacity. \$\endgroup\$
    – sherrellbc
    Commented Apr 11, 2015 at 0:52
  • \$\begingroup\$ Are your really sending 9V to a pin on the RPi?? \$\endgroup\$ Commented Aug 19, 2015 at 12:45

2 Answers 2

1
\$\begingroup\$

Add a pull-up or pull-down resistor. Try 10k. If that doesn't work, try 1k. My guess is that your long wire is picking up some EMI and the very high impedance GPIO pin is converting that to a high enough voltage to change the pin state. A pull-up or pull-down resistor will make this more difficult.

\$\endgroup\$
0
\$\begingroup\$

Based on the schematic you've supplied, your motion detector is either connected as a short, leaving the GPIO floating or it applies VCC to the GPIO. It doesn't show that there is a common ground reference. Perhaps the circuit is incorrect.

First, make sure that the circuits at both ends of your wire share a common reference (GND). Voltage must be measured relative to a reference. If each side of the wire has its own uncommon reference, then the sensor is essentially always floating on the GPIO input.

If there is indeed a common ground on both ends of your circuit, you should pull the input either high or low with a resistor to ensure that when left open, it will not be left floating. The connected device may already have a pull up/down, but one isn't shown in the schematic. Even if you measure ~0V DC, there is likely some AC EMI picked up on the floating input, especially with a 30ft wire attached.

With such a long wire attached, even if the input is not floating, you may be picking up enough EMI to overwhelm the weak drive strength of your sensor.

\$\endgroup\$
5
  • \$\begingroup\$ To pull the input down, could I just connect a 10k resistor from the control wire to gnd before it hits the gpio? \$\endgroup\$
    – globby
    Commented Apr 11, 2015 at 0:47
  • 1
    \$\begingroup\$ @globby, if you are using a PIR sensor and driving the line with the "output" of this sensor then this has likely already been done for you; check the datasheet to be sure, but I would guess the output is either high or low and never floats. \$\endgroup\$
    – sherrellbc
    Commented Apr 11, 2015 at 0:49
  • 1
    \$\begingroup\$ @sherrellbc This is true, of course depends on the circuit/connected device. Based on the simple schematic provided in the question, it looks like a float (could very well be something different). \$\endgroup\$
    – shibley
    Commented Apr 11, 2015 at 0:52
  • \$\begingroup\$ The PIR sensor is straight from Adafruit. adafruit.com/products/189 They don't supply a definitive datasheet that I can find, except for this one: learn.adafruit.com/system/assets/assets/000/010/136/original/… which has little information and isn't the exact model they sell (though they reference it) \$\endgroup\$
    – globby
    Commented Apr 11, 2015 at 0:54
  • \$\begingroup\$ don't buy a sensor without a definitive datasheet. \$\endgroup\$
    – Aenid
    Commented Aug 19, 2015 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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