Switch Bounce

This blog post on switch bounce is an excerpt from Lesson B-5 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.

 

When designing electrical circuits containing switches, it is important to account for and possibly correct for switch bounce depending on the nature of your circuit and what other components are affected.

When switches are opening or closing, metal plates called contacts must come together or move apart to control the flow of electricity through the switch. These plates are made of metal, so they will conduct electricity, but this metal-to-metal contact can result in the two plates bouncing off each other a very tiny amount, until they settle either fully together, or fully apart. Switch bounce is the microscopic movement which can result in the switch being open and closed very quickly, typically less than one millisecond, until the switch settles into the desired state.

All mechanical switches will exhibit some level of switch bounce, but it may not be a problem in their specific application. For example, the light switch in your room has switch contact bounce but you don't see the light flash on and off multiple times when you flip the switch on. This is due to the latency in overhead lighting and most other electronics.

Switch bounce may become a problem depending on how you plan to use the switch input. If the program just turns on an LED based on switch input, then bounce won't really be a problem. Extremely rapid on/off LED activity will be masked by the amount of time it takes the LED to turn on and off, so the LED will appear to turn on and off smoothly, even though switch bounce is still occurring.

The problem occurs when you have the ability to check a switch very quickly, like the Raspberry Pi is able to do, thousands of times per second. Imagine you have program that is supposed to keep track of how often you drink water each day. Each time you drink a glass of water you press a pushbutton, and the program keeps track of how many times the switch went from low to high, adding to that count throughout the day.

Pressing the button quickly, only one time, should result in one being added to the current count. Due to switch bounce, there may be a few extra low to high transitions for every time the button is pushed, and these will all be logged to the counter.

Switch Bounce Diagram

Pressing the button 8 times throughout the day might result in a final count of 32 glasses of water, which is obviously very inaccurate. Removing these extra counts is called debouncing, which can be done via hardware using additional components, or via software.

In Lesson B-5 of our Intro to Robotics program, we teach you to write debouncing code in Python so you can correct for switch bounce as needed in your electronics projects.

This blog post on switch bounce is an excerpt from Lesson B-5 of our Intro to Robotics program. Level B is the second level in Intro to Robotics and covers working with electronic components (including a variety of sensors), writing intermediate-level code commands in Python, and using a Raspberry Pi to control your electronics projects with the code you write. It contains 18 lessons including 65+ videos and 50+ projects and activities. Sample lessons and a full scope and sequence for Level B can be found here.

Older Post
Newer Post
Close (esc)

Popup

Use this popup to embed a mailing list sign up form. Alternatively use it as a simple call to action with a link to a product or a page.

Age verification

By clicking enter you are verifying that you are old enough to consume alcohol.

Search

Your cart is currently empty.
Shop now