Microcontroller input problem - interference - limit switch - Page 1
Forum section: electronics / beginners

author: tango17
author_rank: Regular Contributor
timestamp: June 11, 2022, 08:09:55 pm
content: I have a TV lift that raises/lowers the TV. I want to modify it it to stop at a specific position. I've installed a limit switch that closes when it reaches that position.Background: The lift has a control box with multiple membrane switches that can be assigned to stop the lift at any desired position. Each membrane switch is connected between ground and a corresponding input to a microntroller. Each input also has a 10K pullup resistor from the input to 3.3 volts Vcc. Simple.If the lift is not moving, pressing a membrane switch pulls the corresponding input to Low (ground) and releasing the switch returns the input to High (3.3 v). The controller responds to that by driving the lift to the assigned position for that input.

author: tango17
author_rank: Regular Contributor
timestamp: June 11, 2022, 08:23:01 pm
content: I want my limit switch to stop motion of the lift when it closes, regardless of where the lift is going.If the lift is moving, pressing a membrane switch (any switch) and releasing it will stop the lift.My first attempt: I connected the limit switch to a microcontroller input and then to ground through a capacitor. When the lift hits the limit switch, the discharged capacitor pulls the input Low. The capacitor then charges through the 10K pullup resistor pulling the input High.This works (with problems described below). When the TV moves away from the limit switch, I need to discharge the capacitor. I do this with a 100K resistor in parallel across the capacitor. Thus the input only sees about 3.0 volts for High with the limit switch closed, but this no problem.

author: tango17
author_rank: Regular Contributor
timestamp: June 11, 2022, 08:41:09 pm
content: The problem is that the TV lift is flakey with this modification. It acts as though it randomly sees other button presses and stops moving, even when nowhere near the limit switch.To debug, I have tried removing my mod. After removing the capacitor, switch wires and the 100K bleed resistor, It is still flakey! (Although less so.) All that I have connected are three short wires (ground, 3.3v and the input) each less than a few cm in length. Those 3 wires are held down with some hot melt glue for strain relief.Removing the last of the mod, just the glue and wires, fixes the problem. Remember, for this debug test, the wires go nowhere. They just connect at one end to ground, Vcc, and the input.Presumably I'm getting some sort of interference, although without the cap, bleed resistor and limit switch wires the flakiness is significantly reduced. Touching the disconnected ends of these wires makes the problem worse.Can anyone suggest a solution? Should I be trying to add a filter cap at the input? Presumably it is seeing enough of an interfering signal at the input to cause the controller to stop what it's doing and stop moving (that's what I mean by "flakey" - it randomly stops moving.)Suggestions? Thanks.

author: ledtester
author_rank: Super Contributor
timestamp: June 12, 2022, 12:03:48 am
content: Quote from: tango17 on June 11, 2022, 08:41:09 pmHow long is the wire from the microcontroller to the switch? It sounds like it is acting as an antenna and picking up EMI.Have a look at this article:https://www.digikey.com/en/articles/protecting-inputs-in-digital-electronicsIt would be helpful to see the exact schematic of the switch/microcontroller interface with component values. For instance, how big is your capacitor? From what I read I don't think you have a series resistor like the 1K that the Digikey article talks about.

author: rstofer
author_rank: Super Contributor
timestamp: June 12, 2022, 12:52:00 am
content: Sometimes, mechanical switches don't work well with very low current and low voltage. The voltage isn't high enough to break through any oxidation and the current isn't high enough to maintain continuity. That's why precision switches have gold plated bifurcated contacts.But it sounds like you have other problems. Still, I would change the 10k resistor to something on the order of 1k if that is possible.Maybe a magnetic reed switch would have better contacts and be designed for low signal levels.

author: tango17
author_rank: Regular Contributor
timestamp: June 12, 2022, 05:28:21 pm
content: Quote from: ledtester on June 12, 2022, 12:03:48 amIt's about 2 meters, but the problem occurs with no wire connected at all. The input with the 10K pullup is hypersensitive. Connecting almost anything intermittently triggers that input.QuoteThank you! That's perfect. I suspect I can use the info there to solve my problem.