5

I'm planing on putting up a magnet and a reed switch on my window at home and I'm planing on using a RaspberryPi to sense when it's open/closed. I'm going to pull the wire up in the attic so the distance can vary a bit from 3 meters to maybe 20 meters.

My question is if I'm going to run into trouble having so long cables? I found a 0.50mm²/20AWG cable that I was planing on using.

PatricF
  • 173
  • 2
  • 5

2 Answers2

9

You won't run into problems if you do it correctly :) Let's go over a few basics:

  1. You're talking about switching dry contacts in a reed switch, so you should size your pullup (or pulldown) resistor to keep the current in a range of 1 to 5 milliamps.

  2. Long-ish cables can act as an antenna to pick up "EMI", so you'll need a simple "filter" to squelch spurious signals. We'll cover that filter in a moment.

  3. Using a twisted, shielded wire pair (instead of two discrete wires) can help reduce noise pickup. If you don't have a STP wire, simply "twist" the pair of wires you do have. A twist every inch or two will be fine.

  4. Situations vary! You will have some spots in your house that have more interference than others. Consider this when you're planning your signal wire routing, and try to avoid adjacency to large current users (ovens, heat pumps, etc).

The "filter": I'll assume you don't have a lot of instrumentation, and so we'll approach this as a trial-and-error effort. Keep things simple... it's silly to worry about problems you don't have - you'll never run out of problems to solve, so don't waste time solving those that don't exist. That said, the filter you should start with is very simple: a 0.1 uF capacitor. Place it near your GPIO pin: one end to the GPIO pin, the other to Ground.

If you find that you are detecting "false triggers" from time to time, perhaps the easiest thing to try first is a "software timer". In other words, when your GPIO pin is pulled to its "active" state, start a counter in software; count to perhaps 500 msec, then check the GPIO pin again. If it's in the "triggered" state (active), then you have a "real event". If it's not, it was a spurious signal.

Try this, and let us know if you have any other questions, or run into difficulties. Also know that our SE site has a "schematic tool" that may be useful if you need or want more details on pin connections, component values, circuit diagrams, etc.

Seamus
  • 23,558
  • 5
  • 42
  • 83
0

If you're referring to the cables that you stick on the GPIO pins, they work on 1-5 V typically,on arduino they have higher voltages, so the voltage will fall slowly with distance. i wouldn't suggest using longer cables. You can however move the RPi to the attic or wherever you need it and connect it wirelessly to your pc via SSH, or you can even extend the monitor cable from the pi to your room depending on how you want it, there are many ways around this problem, but using 20m cables with 5V, I'm afraid simply won't work.