Can I connect input pins directly to +5V?

I've got quite some experience with Arduinos now but a doubt is growing in my head about this latest project.
The idea is for the Arduino to read the state of up to 16 reed switches.

The reed switches are in fact "window open/closed sensors" at a friend's house. As such they are on relatively long cables going through the house (estimated up to 20 metres). That's why I don't want to connect these cables/sensors directly to the Arduino but use some sort of driver to protect the Arduino from any spikes that might come from these long cables.

Now, I could use 16 transistors but I have quite a few UDN2981 (8 source drivers) lying around and was going to use these with some pull-up and pull-down resistor arrays.

The UDN2981 would basically switch +5V to the Arduino input pins when the remote reed switch is open. When the reed switch is closed (to GND) the UDN output would be open and the pull-downs would pull the Arduino input low.

I would of course need to disable the internal pull-ups.

That's the theory in my head. Would it work this way or is this a bad idea? Should I rather put limiting resistors in-line between the UDN and the Arduino?

Arduino_Devices_contacts - Schematic.pdf (42.1 KB)

i would try to use the internal pull-up resistors first...
like this:
arduino pin -----------------20m------------cable---------------- reed ||||| reed ---------- GND
maybe it might be good, to insert a 1k resistor (in series) between the arduino pin and the long cable...
and some additional protection schottky diodes close to the arduino pin (one that points to 5V and one that points from GND)....

if u r afraid that those 20m cables act like an antenna and inject false signals (which they could do to those UDN2981, too...), u could put an ATtiny close to each reed switch... and then connect all those ATtiny-s to one bus...

if u r afraid of lightning, u could make that bus out of optical fibre thingies:

Pins configured as inputs can be connected directly to +5V without a problem. Input pins have very high impedance, so effectively little or no current will flow. A risk would be if a pin is mistakenly configured as an output and driven low while connected to +5. As RIDDICK suggests, a small series resistor (as low as 220?) will effectively protect against this by limiting the current drawn.

Not sure how appropriate the UDN2981s are, their usual purpose is to provide higher drive currents, which isn't needed in the case of an input pin. While they do represent another device between the MCU and the reed switches, and would therefore provide perhaps some amount of protection, I'd prefer circuitry designed with that specifically in mind.

Maybe a Ruggeduino would be useful: http://ruggedcircuits.com/html/ruggeduino.html

What sort of cable is used to wire the reed switches? Twisted-pair (good) or shielded cable (better) will limit noise pickup. I might use smaller pullup resistors, maybe 1K instead of 10K. This will increase the current drawn when the switches are closed, but will also increase noise immunity (higher signal-to-noise ratio). A small capacitor to ground (maybe 100nF) might also be prudent to bypass any high frequency noise.

Bottom line, I don't think there is a huge risk of false signals here. But I'd probably try it to see. Construct some simple prototype for a couple switches. Leave it in place for a couple days (or weeks) and see what happens. Have the code latch an LED on or something if a false signal occurs.

EDIT: Like any mechanical switch, these should be debounced. That will also work to improve signal quality.

HTH

You will need good protection circuitry if the cables run alongside mains cables (these can have kV level spikes on them which would induce crosstalk voltages easily capable of frying the Arduino.

I'd suggest for protection using a 10k resistor in series with the cable at the Arduino end and a 100pF to 1nF capacitor to ground on the input pin. The chip's protection diodes ought to do the rest (adding schottky diodes will be more rugged). Since the application doesn't require high speed operation the low-pass filter formed by the resistor and capacitor won't be an issue.

You will need to debounce the signal since it comes from a relay.

Thanks for your replies.

So I understand that in theory my circuit would work (phew) but it's not ideal. I need better protection.

I haven't seen the wires installed in his house myself. He is in Germany and I'm in the UK. This is also why trial and error is not very practical in this case. I'm building this for him and it should then work at his place when I post it to him. So I rather over-engineer it a little. :wink:

From what he tells me these are single pair wires connected to the reed switch on each window. Not sure what type of cable they used. Will ask. I doubt it's shielded.

There is also no power by the windows, just the reed switch. So running anything active near the window (like the suggested ATtiny) is out of the question. Also, for the same reason and because the cables are already installed, fibre-optics are ruled out too. :slight_smile:

I'll edit the schematics with the suggestions made here and post it again.

MarkT:
You will need good protection circuitry if the cables run alongside mains cables (these can have kV level spikes on them which would induce crosstalk voltages easily capable of frying the Arduino.

I'd suggest for protection using a 10k resistor in series with the cable at the Arduino end and a 100pF to 1nF capacitor to ground on the input pin. The chip's protection diodes ought to do the rest (adding schottky diodes will be more rugged). Since the application doesn't require high speed operation the low-pass filter formed by the resistor and capacitor won't be an issue.

You will need to debounce the signal since it comes from a relay.

Do you mean I should get rid of the UDNs alltogether or add the resistors and capacitors to the circuit with the UDNs still there? I wish there were capacitor arrays just like the resistor arrays. 16 capacitors to GND is going to be a nightmare on Vero board. :smiley:

Regarding debounce, the idea was to read the switches every 10 seconds or so, not continuously. I was hoping that I wouldn't need debouncing in that case. Even if one read-out was wrong, 10 seconds later I would have the correct state.

You could test at your place easily enough. I'd start with a circuit like the attached. I'd definitely use software debounce as well, probably for some ridiculously long time like 100ms. There are several debounce libraries out there. My favorite is the one I wrote :smiley: GitHub - JChristensen/JC_Button: Arduino library to debounce button switches, detect presses, releases, and long presses

Sorry about the capacitors...

input circuit.png

Thanks a lot for that circuit. I have modified my schematics and attached it again. I take it that Zener can be any 5V Zener? Or is there any particular reason why you chose that model?

Just after I posted my previous reply I did realise that I could test at my place with a 20m cable. :slight_smile:
What I couldn't test is any potential interference caused by specific wiring at my friend's house. But he assures me that these cables do not run parallel to mains cables. In fact, the window contact cables go through the ceiling while mains power is wired through the floor. This is a single storey house (i.e. a bungalow).

Apology accepted... :smiley:

Arduino_Devices_contacts - Schematic.pdf (47.1 KB)

Oh, and I will have a look at your debounce library, thanks for that!

yesyes:
I take it that Zener can be any 5V Zener? Or is there any particular reason why you chose that model?

Nah, just grabbed it from an existing schematic. Should be non-critical. That one is actually a 5.0V Zener, but I'd think most any garden-variety type would work. 5.1V may be a more common value. 4.7V should work as well for that matter.

Just after I posted my previous reply I did realise that I could test at my place with a 20m cable. :slight_smile:
What I couldn't test is any potential interference caused by specific wiring at my friend's house. But he assures me that these cables do not run parallel to mains cables.

I might even gin up a scenario where the cable does run parallel to mains, etc.

yesyes:

[quote author=Jack Christensen link=topic=112831.msg848961#msg848961 date=1341433730]
Sorry about the capacitors...

Apology accepted... :smiley:
[/quote]

XD XD

cant u use pin 13 of the minipro instead of the permanent +5V at those pull-up resistors...?
that would save a lot of power...
somebody else here had that idea before... me too lazy to look up his/her name...

Ah, you mean connect the common side of the pull-ups to pin 13 instead of +5V, set pin 13 as output and normally on LOW. Then, before I check the switch states, set pin 13 HIGH, read the switches, then set pin 13 LOW again? That sounds like an excellent idea. Thanks !

yup...

and MarkT recommended a 10kOhm protection-resistor instead of the 220Ohm resistor...

So this would be the final version?

Quick question on the Zeners, just so I understand this right... They prevent the voltage on the input pins from rising above the Zener voltage, right?

Arduino_Devices_contacts - Schematic.pdf (50.5 KB)

RIDDICK:
yup...

and MarkT recommended a 10kOhm protection-resistor instead of the 220Ohm resistor...

I assumed that was if I kept the UDNs. So you would also recommend going for a higher value on the series resistors?

regarding pin13 as pull-up, I should probably wait a while between setting pin13 HIGH and reading the switches for the capacitors to charge?

OVER LOAD ALERT :blush:

if u drive 16 1kOhm resistors from 1 arduino pin, u will get 80mA, which is too much for a single pin...
so u should use 3kOhm resistors...
or a mosfet as a driver (the arduino pin goes to the gate)...
or a bjt...

oops

Thanks for that. I'll use 16x 4k7 then, that adds up to 17mA.

kewl :slight_smile:

I've managed to solder this on a rather small footprint last night.. :wink:
Not tested yet, will report back how it works.

Thanks again for all your help! Much appreciated. :slight_smile: