Electronics & Circuits Series

Debounce analog switch contacts noise

TL;DR

A bouncing effect of the analog switch button can be reduced to minimum by simple RC low pass filter which can be upgraded by diode to allow faster switching.

When I started working on one of my projects “Pinball” I faced problematic issue with the noise generated by the analog switch. I plan to have many analog limit switches in my project so I can’t have “noisy switches”. The problem illustrates an image below:

Analog switch contacts bouncing effect.

Switch has analog contacts that bounce few times before they are touching each other in stable state. That bounces – vibrations, generate a noise that we can observe above. Each time we switch ON or OF, the metal contacts bounces a little bit for some time, that we can call “bounce time”, and after that period we see stable state – switch is actually switched. We can see it below.

Analog switch bouncing effect (source: Forbot)

Why is it a problem?

Normally when you use analog switch to turn ON/OFF a light bulb or a motor or other analog device, it is ok. The problems appear when you want to drive a controller pin, like Arduino or, like in my project, ESP8266 Node MCU. Microcontrollers are more sensitive (TTL/logic devices) that detects any such kind of noise. Controller will detect that bouncing as a fast switching ON and OFF of your button. It may be solved on software side, adding some delays, software debouncing, but I’m not a fan of that kind solutions.

First, that really complicates you program logic, and easy part like switch handling becomes a hard thing.

Second, I’m a fan of clean solutions, the problem is on hardware side, solve it in hardware.

RC filter to the rescue!

To make the switch smoother I used an RC low pass filter shown below.

RC low pass filter

It worked great! But…after some tests I noticed another problem – when I was switching very fast, some “states” were simply skipped at OUT pin. When I started switching button ON and OFF faster and faster I got to the moment, when I was switching so fast, that it was not detected at all. The capacitor in the RC circuit was not discharged that fast, so next switch, just sustained previous state. I had to find a solution to force capacitor to discharge faster, to allow my switch to be switched ON/OFF faster, and to still detect it correctly in my ESP8266 interrupts.

Final solution

The solution was to add a diode for \(R_2\) resistor.

RC low pass filter with diode

As you can see, I increased also the \(R_2\) resistance to increase also the voltage on diode, to make the diode work as expected here. An effect is the smooth rise and fall as we can see below.

Debounced analog switch noise.

I tested the circuit manually by pressing the button really fast and it was working all the time. The interrupts were triggered correctly. I’m not so experienced to tell you what is the minimum delay between ON/OFF switches that will be detected correctly, but it seems to be about 20-50ms, it looks like c.a. 50Hz should be supported.

I hope that it may help someone, thank you for reading.

About Paweł Porombka

A full stack developer working commercially with Node.js and Angular stack. Really likes to work on UI/UX designs and DIY projects. Interests: Programming, UX/UI design, Guitar, Electronics, Fischertechnik, Wood. Favorite movies: "Next" & "Back to the future". Favorite music: Rock, Blues, Metal.

Leave a Comment

Your email address will not be published. Required fields are marked *