0
\$\begingroup\$

I'm trying to read the state of a switch with an Arduino. The switch is being pushed each time a garage door opens or closes, and is located about 2 meters away from the Arduino. The cables connecting the switch to the Arduino are running alongside a conduit carrying a 220V cable.

Everything works fine and the switch states are read correctly, but when I operate the electric window on the floor above the garage, the Arduino also registers a press of the switch. After hooking up my oscilloscope to my circuit, I noticed a 472ns pulse of +100V coming over the cables connected to the switch. I did not measure the exact voltage, I guess it's closer to 220V, but I fear any voltage that high might damage the Arduino.

Using the Falstad simulator, I tried to create a solution for this problem, but I'm stuck and I don't know how to continue. Here is my simple circuit so far: simple voltage clamp circuit

Normally, the Arduino reads 0V. When I press the switch, the Arduino reads 5V. When a pulse comes through, the zener diode clamps the voltage to just below 5V so the digital pin won't be damaged. The only thing that's still wrong, is the original problem! A voltage spike is still registered...

Basically I'm left with two questions:

  • How do I prevent the voltage spike from being registered by the Arduino? I've solved it in software by not registering pulses smaller than 10ms (a switch press by the garage door takes 400ms), but I'd like to solve it in hardware. I'm guessing I need to use a capacitor, but I can't figure out how and where to place it...
  • How does the voltage spike register in the first place? I get that it's interference from the cable running alongside the switch cables, but when the switch is open, there is no circuit for current to flow. Does that mean there's a voltage without current? How is that possible?

A colleague already warned me never to let digital pins float, but I'm not convinced that this is the case here. When the switch is open, the digital pin is connected to ground via the 1k resistor, if it's closed, it's connected to 5V, so the pin never floats.

Thanks!

PS:

  • the 1ohm resistor was added because Falstad deals with ideal components. If the pulse was connected directly, I'd get a matrix error, hence the resistor.
  • I've decided to ask this on Electronics and not Arduino, because besides providing 5V and reading a voltage, I don't think the fact that it's an Arduino matters to this circuit. Using a power supply and a voltage probe would yield the same result imho.
\$\endgroup\$
4
  • \$\begingroup\$ 100V spike at the Arduino I/O input pin ('scope measurement)? That may be a bogus measurment - your circuit protection seems reasonable. To be safer, you might insert a series resistor between Arduino I/O and zener+1k. Something like 100k \$\endgroup\$
    – glen_geek
    Oct 15, 2021 at 23:49
  • \$\begingroup\$ @glen_geek I know. Funny thing though, the arduino was already running for a few weeks before we even found out WHY the alarm went off without the garage door being opened, so obviously the Arduino survived those peaks! ... which is not to say that the current situation is a good one, obviously. \$\endgroup\$
    – Marlon
    Oct 15, 2021 at 23:53
  • \$\begingroup\$ You have 2 long wires to the switch (one to Arduino's +5v, the other returning to 4.7V zener). These should be paired close together, ideally a twisted pair. That might help keep transients excluded. Hopefully, Arduino's +5V line has a robust bypass capacitor to its Vss (gnd). \$\endgroup\$
    – glen_geek
    Oct 16, 2021 at 0:09
  • \$\begingroup\$ @glen_geek as I commented on the answer Dennis Ernst gave me, I tried to swap the cable for a Cat5e network cable, using one of the twisted pairs, but I got the exact same result. I don't know why, because I thought the twisted pairs were supposed to prevent this sort of thing from happening... \$\endgroup\$
    – Marlon
    Oct 16, 2021 at 0:19

3 Answers 3

1
\$\begingroup\$

Personally I prefer low side switching that keeps the logic power in the controller with most of the external noise excluded. I would pull up the arduino side of the switch with maybe a 1K pull up at the arduino end in series with a 100K to the arduino pin. You can also add a small cap at the arduino pin if you like. The junction of the two resistors goes to the switch. You now have a switch that grounds the input and the arduino and requires several mills in the switch circuit for the arduino to see the signal. Note the signal will now be inverted which requires a minor software change. I have never really worried about voltage, the internal microprocessor pin protection diodes are normally rated in current. You need to put at least that much current into the port before the voltage starts to rise over or under the Vf of the protection diode and damages the microprocessor.

\$\endgroup\$
0
\$\begingroup\$

The problem you encounter is called crosstalk. Crosstalk happens when two electrical conductors are inductive or capacitive coupled. For your case I guess its the inductive case, since your signal wires run along the mains wires. A current spike in the mains wire induces a current in the signal wire, hence a voltage spike. This specific case is called common mode noise.

One strategy would be to change your cable routing, so the mains cable cannot effect your signal wire.

Another strategy could be the use of a low pass filter on the input of your ardunio - you already implemented one in software. In hardware this would be a simple RC-circuit with a time constant greater than 10ms.

Last but not least the most robust but more complicated strategy would be the use of a differential pair for your garage switch. A differential pair takes, as the name says, the difference between two signals. Since the common noise is induced on both conductors the difference wont change. For example you can use some RS422 transceivers for this task but this might be overengineered.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your quick and elaborate answer! Unfortunately I'm unable to change the routing of the cables, so I'm guessing in my case the RC circuit would be the ideal solution. I've tried to read up a few articles on RC circuits, but cannot quite grasp how or where to add these components in my existing circuit. Either my changes don't do anything, or they affect the behaviour of the switch as well... Would you be so kind as to elaborate on your answer a bit more, perhaps with a schematic I could understand? I would be very grateful! \$\endgroup\$
    – Marlon
    Oct 15, 2021 at 23:49
  • \$\begingroup\$ Oh, one more thing... I was under the impression that network cable was designed specifically to prevent this sort of crosstalk, so I tried swapping out the existing cable for a network cable (Cat5e), and I used one of the twisted pairs to connect to the switch. Unfortunately, after hooking up the scope again, I saw the exact same behaviour. Why did the network cable not solve the issue? \$\endgroup\$
    – Marlon
    Oct 15, 2021 at 23:50
0
\$\begingroup\$

Twisted-pair must be combined with other technologies to be effective. One of those things is that you have to reduce spikes to manageable levels first (and then the right OpAmp, with its differential input {and good common-mode-rejection-ratio CMMR rating}, would filter out the rest). My suggestion is to first reduce your spike significantly, and start by finding the right common mode choke. Not sure if this one will work for you, but this $3 each (@ 10 qty) common mode choke toroid helps to resist surges and lightning strikes on a house line.

enter image description here

I consider the above to be strong filtering. Below is a $0.77 each (in 10 qty) "Cable Ferrite", which you would use to take your wire and put one or more (I would put at least 2) turns around the ferrite, basically making the same circuit as the toroid above.

enter image description here

I've seen these put on both ends of the cable as well. So, you may need to do that. Apply enough common-mode filtering to reduce common-mode spike that you're getting from the 220v cable.

If you do dumpster diving, big electronic devices usually have one or more of both of these. (Make sure you safely discharge any large capacitors, first!)

Hopefully, that's all that you really need. If not, you can ask a different quesition to get the right OpAmp and circuit to achieve the rest of the filtering.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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