Go Down

Topic: Can I connect input pins directly to +5V? (Read 2793 times) previous topic - next topic

yesyes

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?
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

RIDDICK

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:
http://en.wikipedia.org/wiki/Optical_fiber
-Arne

Jack Christensen

#2
Jul 04, 2012, 03:22 pm Last Edit: Jul 04, 2012, 03:26 pm by Jack Christensen Reason: 1
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
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

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.
[ I won't respond to messages, use the forum please ]

yesyes

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. ;)

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. :)

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


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. :D

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.
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

Jack Christensen

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 :D https://github.com/JChristensen/Button

Sorry about the capacitors...

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

yesyes


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 :D https://github.com/JChristensen/Button


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. :)
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).


Sorry about the capacitors...


Apology accepted... :D
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

yesyes

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

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

Jack Christensen


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.

Quote
Just after I posted my previous reply I did realise that I could test at my place with a 20m cable. :)
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.

Quote from: yesyes


Sorry about the capacitors...


Apology accepted... :D


XD XD
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

RIDDICK

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...
-Arne

yesyes

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 !
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

RIDDICK

yup...

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

yesyes

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?
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

yesyes


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?
Chris

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

yesyes

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

Location: Berkshire, UK
My Astro and DIY projects website: http://yesyes.info/

Go Up