FSM Lecture 29- Button bouncing explanation

  • Post author:
  • Post category:Blog

 

Button bouncing explanation

 

 

In this article, let’s discuss the button bouncing and discuss how to debounce it using software later.

Button bouncing, also known as switch bouncing or contact bounce, is a phenomenon that occurs when a mechanical switch or button is pressed or released. It refers to the rapid fluctuation of the electrical contact between the switch terminals during this transition, resulting in multiple open-close cycles within a very short time period.

When a button is pressed, the metal contacts inside the switch come into contact with each other, creating a closed circuit. However, due to the inherent mechanical properties of the switch, such as the elasticity of the materials and the presence of springs, the contacts do not make an immediate, clean connection. Instead, they may momentarily bounce off each other before settling into a stable, closed state.

Similarly, when the button is released, the contacts separate, breaking the circuit. Again, bouncing can occur as the contacts physically disconnect, causing momentary interruptions in the circuit.

 switch is open
Figure 1. Push button interfacing to Arduino using Pull down resistor( switch is open)

 

Figure 1 shows how we interface the push button to the Arduino board. We actually interface the push button using a pulldown resistor, so you can even do it using a pullup resistor.

There is a switch, and the pulldown resistor of 10k is going to the ground. When the switch is not pushed (when the switch is open), the Digital pin is connected to the ground via the pulldown resistor. That means the Vin, which is 0 volt. It looks like this, shown in Figure 2.

Push button interfacing to Arduino using Pull down resistor(switch open)
Figure 2. Push button interfacing to Arduino using Pull down resistor(switch open)

 

If you measure the voltage at Vin point, the multimeter shows 0 volt. 

 

Button bouncing
Figure 3. Push button interfacing to Arduino using Pull down resistor(switch is close)

 

Suppose, if you close the switch, the Vin point is connected to 5 volts. It looks like this, as shown in  Figure 4.

Push button interfacing to Arduino using Pull down resistor(switch close)
Figure 4. Push button interfacing to Arduino using Pull down resistor(switch close)

 

Vin connected to the 5 volt. If you measure the voltage, it shows you 5 volt. 

So, the circuit looks something like this. There is a pulldown resistor going to the ground, and there is a battery of 5 volt, and the Vin point is going to the pin.

When the digital pin of the microcontroller is in the input state or input mode, its input impedance is very high in terms of Mega ohms. That’s why, when you close the switch, there is no abrupt increase of current.

The current will not move inside this microcontroller pin. Because of its input impedance, the pin input impedance is very high. So, no current flows actually except some leakage current. That’s why you need not worry about a lot of current sinking into the pin. It doesn’t happen because of the input impedance of the pin. 

But if your code mistakenly configures the mode of the digital pin as an output, then the input impedance suddenly drops, and a large current may sink into the pin, and it may damage your pin. That’s why it’s better to introduce one more resistor here(as shown in Figure 5), that is the current limiting resistor in the path. Maybe around 220ohm or something. This is our interfacing.

Implement a resistor in path
Figure 5. Implement a resistor in path

 

When the button is not pressed, the pins state is 0 volt; when pressed, the pins state goes to 5 volt. But, in reality, the transition is not this smooth. In reality, the pin’s transition from 0 volt to 5 volt or 5 volt to 0 volt looks like this( as shown in Figure 6).

 

Button bouncing
Figure 6. Button Bouncing

 

Button bouncing is shown in Figure 6. That bounces between 0 volt and 5 volt a couple of times before settling for either 5 volt or 0 volt.

Why does this bouncing happen?

It happens because of mechanical contacts.

What is a switch?

A switch is nothing but a mechanical contact. Mechanical contact or metal contact is shown in Figure 6.

When you push one metal contact on another metal contact, one metal contact tends to bounce upon the other metal contact. There is a slight disengagement.

When you touch one metal contact to another metal contact, they bounce of each other. I mean, there is a slight disengagement and engagement a couple of times. That results in bouncing voltages between 0 volt to 5 volts because of that disengagement for a short time. That time is very short. It could be in terms of microseconds, or in some switches it could be milliseconds. Different switches have different bounce times. And for this application, we will crudely take it as 50 milliseconds.

Strictly speaking, you have to check the bounce period or bounce time in the oscilloscope. You have to verify what the bounce period is in the oscilloscope for your switch. Then you can use it in your application, but crudely take it as 50 milliseconds for our application.  

You can name the different situations of the pin like this. NOT PRESSED state, BOUNCE state, PRESSED state, like that.  Now through software, we have to get rid of this problem. For that, we will use the software debouncing technique. There is also a hardware debouncing technique to get the clean transition. For that, you have to attach the debouncing circuitry between your switch and the digital pin. But, for this exercise, we will go for software debouncing and how to do that I will show you in the upcoming article. 

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.