Switching off AC lights will unintendedly cause wave switch to activate - Page 1
Forum section: electronics / beginners

author: bizkits
author_rank: Contributor
timestamp: October 14, 2020, 06:07:18 pm
content: I have a PCB which I designed and am using for a project.The issue I am facing is when a external appliance (overhead lights) is turned on/off it will sometimes trigger my "Open" button.I highly suspect it is caused by EMI which made my microcontroller read a false positive.The pin for the button is controlled using an ESP32. The pin is pulled high using the internal resistors.Hence a close switched will pull the pin low.I tried leaving out 1 wire from the switch and connecting the other wire from the switch to the "+" of my input and when the lights is turned off, it will give the reading of "LOW" instead of "HIGH".However if I try the opposite, whereby the wire is connected to the GND only, when the lights are turned off, it will not cause the reading to go "LOW".This issue don't always happen but occasionally.Anyone faced such issues or something similar? Any advice or suggestions are welcome.UpdateSo I went ahead to implement the software fix which was adding a debounce of 50ms for the input switch.I manage to test it today and it is working well. So far no false positive input switch activation.The software fix made it easier this time round as I am using an ESP32 which has quite a powerful processor.

author: Slh
author_rank: Regular Contributor
timestamp: October 14, 2020, 07:06:08 pm
content: I'm not familiar with the esp32 module but I assume that the switch input is going straight into the microcontroller digital pin? An easy change would be to fit an external, lower value pull up (say 1-10k, best to experiment to see if it makes a difference) with a small capacitor to 0V (1nf perhaps)Do you have any input debouncing? It would probably be worth having a small RC filter on each of the inputs and then having input debouncing where you don't acknowledge a switch input until its state has changed for around 50ms.

author: TimFox
author_rank: Super Contributor
timestamp: October 14, 2020, 09:35:38 pm
content: Are your overhead lights (old-fashioned) incandescent or (new-fangled) LEDs? Some of the latter are prone to emitting excessive amounts of RF interference. With internal pull-up resistors, it might suffice to put a ceramic capacitor across the switch: if it is too high in capacitance, the transition time on switch opening might be too long for the ESP32 digital input. This should be specified by the manufacturer, perhaps as a maximum transition time. The transition time (often called rise time) is given by T(10% to 90%) = 2.2 RC, where 2.2 = ln(90/10), where R is the internal pull-up resistor value.

author: bizkits
author_rank: Contributor
timestamp: October 15, 2020, 03:21:33 am
content: Quote from: Slh on October 14, 2020, 07:06:08 pmYes the switch input is going straight into the microcontroller. In the schematic, under "Inputs", one wire from the switch is connected to pin 33 and another wire to the ground.Switch Wire 1 --> Pin 33 (ESP32)Switch Wire 2 --> GND (ESP32)As the ESP32 already have a 45K resistor, I am not sure if adding another external resistor is necessary.I haven't tried input debouncing. But that could be a possible solution. I will test it out and make an update here.

author: bizkits
author_rank: Contributor
timestamp: October 15, 2020, 05:14:24 am
content: Quote from: TimFox on October 14, 2020, 09:35:38 pmIt should be LEDs as the lights turn on immediately.How should the wiring be done if I choose to add a ceramic capacitor? (I added an attachment of the way I think it should be connected).I've checked the internal pull-up resistor value is 45Kohm.Following the formula T(10% to 90%) = 2.2(45)C.If T is in seconds, then assuming T = 0.5, 0.5 = 2.2(45)C. Hence C = 99/0.5?

author: TimFox
author_rank: Super Contributor
timestamp: October 15, 2020, 02:12:23 pm
content: The circuit is right, but your calculation is not. The transition time "T" is a specification of the ESP32: what is the maximum rise time (or transition time) that the part can tolerate on a digital input? Normal digital inputs can be unhappy if you change the voltage too slowly, possibly oscillating when the input is between low and high states.If we assume 1 msec (a number I pulled out of the air), then with 45 k pull-up, the capacitor would be 10 nF, which is practical for a ceramic capacitor. That gives RC = 0.45 ms, for 1 ms rise time. For a test, I would start with 1 nF.

author: Renate
author_rank: Super Contributor
timestamp: October 17, 2020, 02:04:28 pm
content: This reminds me of a situation from years ago.A friend built a circuit. Whenever the cleaning staff came through with a vacuum cleaner the circuit would inadvertently have its buttons "pushed".As a challenge and to rib him, I designed and built my own circuit.To prove that it was less sensitive I used a neon sign transformer (15,000 VAC) to draw 1/2" sparks to the inside of the case while operating the buttons correctly.We can go to greater or lesser extents to make sure that a circuit is insensitive to external signals.The first thing is, you have a high impedance signal line (45 k) flapping in the breeze as an antenna.If this is not battery powered, the first thing that I'd do is put in a real pullup, like 2.2 k.That reduces the impedance of the line by a factor of 20.I'd prefer mechanical switches to have a mA or two going through them anyway.You can add hardware filtering (like in the previous posts).2.2 k and 1 µF = 2.2 mS(Note: Using 10%-90%, i.e. 2.2 intervals is not really necessary as most logic switches at more like 37%-63%.)You can add software filtering.

author: bizkits
author_rank: Contributor
timestamp: October 17, 2020, 03:13:03 pm
content: Quote from: Renate on October 17, 2020, 02:04:28 pmThanks for sharing your experience. What were the major difference between your circuit and your friend's circuit? Was it the RC at the input pins?As for my case, the circuit is not battery powered. It is powered using a 24V from a Door controller.If I were to add an external resistor, is my drawing correct (I've attached an image)?Actually, other than this issue, I have a module called the W5500 which is a LAN module. It will "crash" and I have to reinitialize it everytime the lights turns on/off.Does that mean I have to do the same and add resistors and capacitors to each of the pin the LAN module uses?Currently, it is quite difficult for me to do a hardware fix.Hence I'll try the software filtering and update the results here in a few days.

author: Renate
author_rank: Super Contributor
timestamp: October 17, 2020, 03:54:15 pm
content: Not quite. The pullup goes between 3.3V and the pin.