7
\$\begingroup\$

In the current case there is a single signal conductor, tens (hundreds?) of meters long, which serially connects door and window sensors for a whole building. The sensors are simplest possible switches: all doors and windows closed means the electrical conductor is closed, if not, the conductor is open at a random point throughout the loop. I’m connecting the loop to an Arduino UNO board and wonder how strong drive strength I could need and how to design the sending/receiving end.

My current plan is to simply connect GND to one end of the conductor and at the receiving end place a pull-up to 5V, TVS diode and use a GPIO for reading the input. The reasoning is that the pull-up (driving source) should be closest to the receiving end to minimize risk of false readings.

Are there any common practices when designing such long serial signal lines? (And ways to estimate needed pull-up strength?)

Are there different strategies to protect the MCU board in the two different cases of interference when “loop” is closed and when it is open?

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Such a large loop may pick up quite a bit of junk, from long waves to short waves. If you have access to an oscilloscope, definitely do take a look. If the EMI pickup turns out to be a problem, try placing a suitable capacitor across the ends of the loop. Or an RLC low-pass filter - such that the DC function is not hampered. \$\endgroup\$
    – frr
    Commented Jun 26 at 8:48
  • 3
    \$\begingroup\$ I sometimes run an arduino with 4 buttons over a distance of 2000m with just the internal pullups over regular cat5e. with some pairs of RJ45 connectors every 500m. This is software debounced, but nothing special, about what @jonathanjo suggests: 1kHz samplerate, 10 consecutive samples with the same value are considered a transition. \$\endgroup\$
    – ontrack
    Commented Jun 26 at 20:57

1 Answer 1

11
\$\begingroup\$

Software

In software (regardless of the hardware chosen), you basically want debounce code which ignores transients.

There are endless algorithms, but perhaps one that is suitable is:

  • sample at high speed (compared to door openings, perhaps 1 kHz)
  • consider most recent N samples (perhaps 10)
  • output state changes when 2/3 votes change

Hardware

For a few hundred metres, you don't really have to do much, and what you suggest will work fine if you do good debounce in software.

Cat 5 cable is about 200Ω/km. I'd try a 10 kΩ pullup and see how well it works.

But consider an optocoupler: it won't fail-lit and allows a separate power supply for the microcontroller and alarm, so the burglars don't cut the power and break in.

schematic

simulate this circuit – Schematic created using CircuitLab

Another idea

One way to ensure constant current over possibly long wires is to consider technology designed for 4-to-20 mA loop, designed for reliably getting signals from A to B in industrial situations with long wires. It's designed to get an analogue signal through, but you can think of it as a low-power constant-current supply with a preset (the signal input) for the desired current.

The fact that 4-to-20 mA loop technology is ubiquitous means you can get chips for it very cheaply, even if we're not using it as designed. A typical one is Texas Instruments XTR116 series.

Consider the long loop through the door/window switches feeding the input of an optocoupler. Now your long loop is completely independent of your microcontroller.

schematic

simulate this circuit

Such a scheme is going to have a lot less noise than many alternatives.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ So, basically, common industrial practice implies that 4mA should be a sufficient drive strength for most cases for several hundreds of meters of wire? \$\endgroup\$ Commented Jun 26 at 9:30
  • 1
    \$\begingroup\$ Much 4-20 mA loop is done with 24V (but it varies) and some articles use "long" to mean "over 300 metres". In essence you're driving a long wire with something which is designed for that purpose, and so it's likely to work well. Here's an article about 500 m. link. \$\endgroup\$
    – jonathanjo
    Commented Jun 26 at 9:52
  • 6
    \$\begingroup\$ You're not really using a 4-20 mA system here if the signal is switching between 4 mA and 0 mA. The whole point of the signal not going down to 0 is so that 0 can represent "the sensor (or wire) is broken"; here, you have no distinction between a working sensor on an open door and a broken sensor on a closed door. It shouldn't matter for this case, but it does mean that I wouldn't call it a 4-20 mA loop. \$\endgroup\$
    – Hearth
    Commented Jun 26 at 13:56
  • 2
    \$\begingroup\$ @Hearth I completely agree with you: this is just using the chips designed for 4-20mA because they're easy to get and can do this job. A real 4-20 mA system, as you say, uses 4 mA to mean 0%. I reworded my answer to make this clearer, I hope you think it helps. \$\endgroup\$
    – jonathanjo
    Commented Jun 26 at 18:03

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