1

I have a reed switch (actually several reed switches) that came pre-installed in my home as alarm sensors. When the 2 parts are together, the circuit is closed, when the 2 parts are apart, the circuit is open. The sensors are in various parts of the home, so the leads can be varying size. They run through my attic, and they may be routed near appliances, ducting, and potentially 110V wiring. The cable itself seems to be CAT5 wire where 1 pair is used for each sensor. In some areas the sensors are actually in series to create a "zone" that would trigger if any sensor was opened.

I have these switches wired to my raspberry pi through the GPIO pins. One side is wired to a GND pin, the other side is wired to a GPIO pin. I do not have any external resistors or power sources in this circuit.

I initialize all of the GPIO pins with the code:

GPIO.setup(sensor,GPIO.IN, pull_up_down=GPIO.PUD_UP)

Then I monitor the state of the pins with the code:

current_state = GPIO.input(sensor)

The circuit works perfectly for several months, but then 1 of 2 things will happen:

  1. The pin will begin to trigger false alarms, often several false alarms in succession followed by hours or days with no false alarms.

  2. The pin will become stuck either high or low.

I am familiar with basic electrical engineering principles, and I cannot understand why this simple circuit seems to be destroying my raspberry pi pins. I have used (and damaged) several Raspberry Pi's and the result is always one of the 2 above.

I specifically wired them in this manner so that the circuit was connected to the ground pin and not the 3.3V pin on the Pi. My thought was that this would prevent any unintentional current draw. I've read about using external resistors, but I don't believe it is necessary in this circuit.

Any ideas what might be going wrong? I am much less worried about the false alarms and more worried about fixing the permanent damage I seem to be causing to the GPIO pins.

  • Once a pin is stuck, is it permanent? In other words, does power-cycling the Pi restore functionality? – evildemonic Oct 4 '18 at 19:15
  • @evildemonic once either of the 2 scenarios happen above, a power cycle does not fix the problem. The pins will remain stuck or the random false alarms will continue. – Luke Oct 4 '18 at 19:17
  • Somehow an under/over voltage situation is happening, perhaps due to long leads. A GPIO on the Pi with pullups enabled, should survive shorting to ground indefinitely. Stray inductance? Either way, series resistors and/or a pair of 3.3V zeners would provide good protection. – evildemonic Oct 4 '18 at 19:27
  • @evildemonic the leads may be up to 100 feet long and they run through my attic. Is it possible that they are picking up some current from 110V wiring or something else? Could I just use a single resistor on the common ground? What size would you recommend? – Luke Oct 4 '18 at 19:36
  • Hello Luke, I recommend to include that information (length of the wire etc) in the question. It seems to be relevant to the issue and thus potential solutions / answers. – Ghanima Oct 4 '18 at 19:39
1

Do you use shielded or unshielded cables ? how long are the cables ? do they run in their pipes, or along AC mains or other cables ?

I bet the usual problem : long cables act as antennas, catching spurious spikes from every near RF emitter: other cablings, electrical motors, microwaves hovens, etc...

You have to protect your micro with some buffers, passive or active circuit, in front of the pins of your micro. This circuits clamps the spikes.

The inputs pins read many repeated events... because mechanical switch make many tiny clicks every time their contacts move. Avoiding these events is called debouncing, it is possible to do in hardware or software.

Look on the web, there are many solutions and suggestions about clamping and debouncing, like this http://www.kevinmfodor.com/home/My-Blog/microcontrollerinputprotectiontechniques

0

From your comments (which should be part of the question) it appears you have attached long wires to the Pi and run these in a hostile environment.

It is hardly surprising that these act as an antenna, and pick up interference, which can cause false triggering and possible damage.

There are established techniques, which engineers build into circuits to prevent this.

I have written a number of answers to similar questions e.g. Pi 3 reboots when GPIO 13 is given 3V (you can find others by searching this site for interference).

Basically you should use a low impedance circuit - a pullup of no more than 3.3kΩ but preferably 330Ω. Include a series resistor (~10% of the pullup) and a capacitor across the GPIO input.

All switches bounce - reed switches are particularly prone to this - use debounce protection.

Take measures to reduce interference e.g. twisted pair cable which should NOT be run in parallel with power cabling.

There are more extreme measures, but the above should suffice.

  • Let's assume I don't care about bouncing for now. (I don't really care if I get 2 or more alerts instead of 1 when a door opens.) So I believe that negates the need for a capacitor. The code I use configures the internal pull up resistor within the Pi, so I believe that negates the need for an external pull up resistor. That would just leave a series resistor that is missing. I can add that to the circuit and see if it protects the pins from damage in the future. Do you suggest that I determine the value of the internal resistor and use one that is 10% of that? – Luke Oct 5 '18 at 13:35
  • @Luke you have missed the point of my answer; the most IMPORTANT is a low impedance circuit - this means a low value pullup; the internal pullup is ~50kΩ. The series resistor/capacitor is to suppress high frequency transients NOT debounce - to debounce would need an impractically large capacitor (which introduces other risks). In fact a resistor BETWEEN the pullup and the GPIO is better for filtering and protection, and a larger value can be used, but the wiring becomes more complex. – Milliways Oct 5 '18 at 23:48
  • I think I understand now. Is the reason because the low impedance circuit will keep noise from having a significant effect on the voltage level at the GPIO pin? – Luke Oct 7 '18 at 18:41
  • If you just want to make sure the output voltage doesn't exceed 3.3v, and you want to do no other filtering to it, try using a zener diode. If you add about a 1k resistor between the sensors and your GPIO pin, and then add a backwards zener diode connecting the GPIO pin to ground, then it will clamp the maximum voltage of the pin to whatever its zener voltage is. Get one with a Vz less than 3.3V, and you should be good to go. – Josh2003 Dec 26 '18 at 16:33

Your Answer

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

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