Tag Archives: button

Arduino Button Debounce Tutorial

One of the major problems encountered when using push buttons and switches in digital electronics project is the problem of bouncing. When we press a button once it may register twice and when we press it four times, in a row, it may register just twice. This occurrence is due to a property of switches known as bounciness which is as a result of the physical property of the switches.

Contact bounce (also called chatter) is a common problem with mechanical switches and relays. Switch and relay contacts are usually made of springy metals so when a switch is pressed, its essentially two metal parts coming together and even though the connection may seem already made to the user, it may not happen immediately, as a matter of fact, it may make contact on one side – then both – and then the other side –, technically bouncing between in-contact and not-in-contact until it finally settles down. This result in a rapidly pulsed electric current instead of a clean transition from zero to full current as shown in the graph below.

Arduino Button Debounce Tutorial – [Link]

How To Connect Multiple Buttons with MCU Using One Line

One of the biggest problems you could face in your current/next project, is when you’re out of free inputs to use.
Sometimes you can save a lot of inputs using some tricks, and there’re really a lot of them.
In this blog post we’re going to know how you can use many push buttons using only one analog input pin. John Boxall from tronixstuff.com demonstrates how we can do that.

Almost all MCUs come with an ADC unit, which is responsible to convert the voltage from an analog value to a digital one (digitizing), for example Arduino UNO, which uses Atmega328 MCU, has an 8-bit ADC.

ADCs convert the voltage to a number (level), so a 8-bit resolution ADC converts Vin to 256 levels.
By using this fact, we can build a voltage divider using a resistor for each button, using one ADC line and recognize each button.

John used Arduino UNO to implement this hack. He used one of the ADC lines, enabled its internal pull-up resistor and connected the buttons and resistors to it, as shown in the following diagram.

Images courtesy of tronixstuff

So now every button has a unique ADC value as the following:

  • 1023 for nothing pressed (default state).
  • 454 for button one.
  • 382 for button two.
  • 291 for button three.
  • 168 for button four.
  • 0 for button five.

To see the full details of this hack, and to get the source files, you can refer to tronixstuff website.