Can an output pin be an intrance door for interference ???

Hello everybody !
Sorry if this isn't the right place for such a question, this is my first post.
I'd like to know if a pin in output mode, connected to a long wire (about 30 meters) can bring interference inside the arduino.
On my breadboard, all is perfect, but when I use long wires between the arduino and a switch, I have a lot of false triggering.
My question is : will an optocoupler near the return INPUT pin be enough or should I also put an optocoupler on the output pin ?
Thanks for your attention and your eventual answers.
Q

I'd like to know if a pin in output mode, connected to a long wire (about 30 meters) can bring interference inside the arduino.

Yes it can.

will an optocoupler near the return INPUT pin be enough or should I also put an optocoupler on the output pin ?

An opto coupler will not help no matter where you put it. You have to reduce the impedance of the line with decoupling and inductors and low impedance drivers at the Arduino end.

A switch usually requires an pullup resistor. Long connections can be made more reliable with smaller resistor values, the internal pullups are way too high for such long lines.

Use twisted wire. Cat-5 or Cat-6 (ethernet) has four twisted pairs, and is cheap.
You only need one pair for one switch.
As suggested, use a low-ish value pull-up resistor. 1k might work.
A 100n capacitor to ground (on the Arduino side) could also help.
Leo..

Hi,

return INPUT pin

Have you got an input pin also connected to the 30m of wire?

A picture of your project would help.
Also can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.... :slight_smile:

Thank you all for your informed responses and sorry for my bad english.
Here is a picture of my project (from memory because I don't have it with me on business trip).
As you can see it is a fencing scoring box adapted to sabre.
For those who don't know it, every part of the sabre that comes in contact with the opponent's conductive jacket registers a point (the rest is made of priority rules but this is the referee's job)
So, two wires are connected to the sabre. One could be enough to close the circuit when in contact with the opponent's jacket, but, as a matter of fact, two are used, so the sabre's line continuity is constantly checked.
To do so, in each loop, pin 0 is in output mode high and pin 1 is in input mode checking for a high coming from pin 1. Then the pin 0 and pin 1 swap their mode and role, so the sabre is always high, except if one of the wires coming from pins 0 or 1 is broken. In such a case, the sabre is high only during half the loop (only a fraction of a millisecond) and the arduino is informed that one of the two cables is broken and the fencer is warned by an LED.
During the loop, pin 12 is checking for a high coming from the sabre : if a high is read, then it means there is a contact between the sabre and the opponent'ts conductive jacket, then a touch is registered.
As far as I remember, I used 10K pull-down resistors.
Everything works perfecly as long as I use short wires (20 cm) to simulate sabre and jacket on my breadboard. But once I connect the project in the real conditions (30 meter wires), I get false touch registering.
Erros in checking the continuity of the "double" sabre line are not dramatic as this is just an information for the fencer when he is not fighting. But of course absolutly no false registering of a touch is acceptable.
There is something I cannot have any action on : the type of wire (the 30 meter ones) used to connect the arduino to the sabre and jacket. Each club buys it from fencing shop and they are what they are : probably not twisted pair. And worse : they are rolled by a reel ( Favero Electronic Design - electronics for sport ).
From your comments, I realize that :
-I should use pull-up resistors instead of pull-down
-I should lower the value of my pull-up resistors.
-I should use capacitors (but can you advice me on this problem : a touch shorter than 1ms can be ignored by the machine but once the touche is at least 1 ms it MUST be registered. A capacitor's value must be calculated with this data in mind, right ? Then how to calculate this value ?)
Another question : without the long wires, every thing works perfectly on my breadboard. All the false touches happen whith these long wires. Won't this be solved with optocouplers or do I miss something ?
Thanks for reading.
(sorry, I wrote 20m on the drawing, but it is 30m)

The use of pull-up/down resistors depends on the usage of the signal. As a rule of thumb the Gnd line should be the reference for a digital input signal, meaning that the sender pulls the line high, while the receiver holds the line down (at/near 0V) while the contact is open. When the contact is established, the sender must supply enough current to make the receiver sense a logic HIGH level. This current is determined by the minimal HIGH level (>3.5V) and the pull-down resistor (say 1k), in which case 3.5 to 5 mA must flow to make the input sense HIGH. In your circuit the sender has to supply current through 3 pull-down resistors, i.e. up to 15 mA, what's close to the capabilities of a digital output (20mA), but acceptable. When the sender (sabre) side resistors are required only for detecting a broken line, these resistors can be increased to 5-10k, to relieve the output transistors. When you add an capacitor at the input pin, more current will be drawn until that capacitor is fully loaded, possibly exceeding the capability of the output transistor. Then you'll have to put an current limiting resistor (guess 10-100 Ohm) into the line(s), preferably on the sender side, because long cables already form an capacitor.

I understand that you want to detect broken cables to the sabre, but I don't understand why you switch input and output all the time. Switching may introduce false readings. At least I'd suggest an overlapping signal, i.e. turn on the other output and wait a bit, before you turn off the previous output. This will prevent spikes on the lines, whenever another output takes over.

A twisted pair line to the sabre can improve noise immunity, but it may be too rigid for your application. On the receiver side I'd use a shielded cable, with the shield connected to the Arduino Gnd, other end open.

The determination of an hit (>1ms) comes close to the millis() resolution. Eventually use micros() and change the time delay accordingly, the rest of the standard debouncing code can stay as is. I'd not use an extra capacitor for debouncing in this case.

On the sender (sabre) side a broken cable should be recognized even from short spikes, when the broken wires in the cable can detach and attach again when the cable is bended. With proper overlap of the output signals you never should get false readings on this side, otherwise you'll have to revise your cable selection (use a two wire shielded cable?).

Eventually you can use two lines connected to two inputs on the input side as well, connected at the jacket side if there is only one contact for the signal.

BTW how many cables are attached to each fighter? When only one cable is connected, it must carry both the jacket and sabre signals. In this case I'd suggest a cable with 2-3 separately shielded lines, one for the jacket and either one (with two inner conductors) or two (separately shielded) for the sabre. Eventually a standard (audio, headset...) cable is applicable, with a shielded line for the jacket (microphone), and two individual lines (speakers) for the sabre, and a shield around them all or around the sabre lines only.

To summarize:

  • use a shielded cable for the receiver (jacket) side
  • use either a twisted pair or a two-wire shielded cable at the sender (sabre) side
  • add small current limiting resistors to the sabre side pins
  • add sufficient output signal overlap (increase until false signals disappear)
  • use software debouncing on the jacket side, eventually using micros()

Try this and report success or eventual problems :slight_smile:

Thanks a lot.
I'll test and report here.
Have a good week.

Hi,
You need to chat with CrossRoads, he works in the fencing sport area.
You need to change your Subject to "Fencing sabre contact monitor, interference"

I'm sure he has done something like this and rather than re-invent the wheel.

Tom..... :slight_smile:

My fencing scoring machines use a 2.7K pullup to bring the lines high and a 7406 open collector to drive the lines low. Each side has 3 7406 buffered outputs and 3 pullups. The open collecter buffer allows both sides to control the line, one side can have it high while the other's 7406 can pull it low, and the input can read the high or low level.
In sabre there are multiple lights:
your sabre against opponent's lame
your sabre against your own lame
your own broken wire indicator

You have to detect these 3 conditions for each side. One of my fencer's parents is an Embedded Software Engineer and he wrote the code to do it by checking for each condition using blink without delay using 3 outputs (buffered by 7406) and 3 inputs for each side.
My original code was only for epee, which is lot simpler - each side only has a high or low. The low can from a touch, or from a bellguard/grounded strip. If one side saw high/low for 2mS (check rule on the time), then it was a touch (tip was closed). If it saw low/low when high/low was expected then the tip is grounded (tip closed and grounded, no time limit). If it was high/high, then the tip was open (normal state for most of a bout,also no time limit). 2nd side has 40mS to score after 1st side score is detected (valid double touch).

The tricky part, which we haven't quite worked out for sabre - continue checking after a touch is detected, as the other side can still occur - a 2nd touch is allowed to score within I think 120mS after the initial touch (longer time than epee). Or you may have your own weapon against your lame, and the opponent (or you) can score. Or you have a broken wire and either side can score. Right now there is a pause with sabre after a touch before the buzzer goes, we need to get rid of that. I think it comes from using tone() to make the sound, need to change it to blink without delay so it can start as soon as the touch is detected but still allow the 2nd side to score.
(Maybe there is the same pause in epee, but it is so much less it's not noticeable).

But anyway - 7406 works well as buffer, 2.7K pullup. I also added extra protection clamp diodes to the lines; in dry conditions (winter) the kids were building up static electricity dragging their feet on the new unfinished flooring (oriented strand board) and zapping each other, and found they could also upset the scoring machines.
Between the diodes, and later putting polyurethane finish on the floor, that problem went away.

I think a lot of people have the wrong end of the stick. The OP said his pin was in output mode and all the answers have been as if this long wire was an input.