Go Down

Topic: Button FAQ: common mistake - button does NOT work as expected. (Read 2492 times) previous topic - next topic

IoT_hobbyist

Newbie usually runs into trouble when getting started with a button. A lot of people asked on the forum about the same issue.

To avoid this, newbie SHOULD pay attention to the following notes:

1. Floating input problem:
Symptom: the reading value from the input pin is not matched with the button's pressing state.
Cause: input pin is NOT used pull-up or pull-down resistor
Solution: Use pull-up or pull-down resistor. See Arduino Button (with pull-up/pull-down)

2. Chattering phenomenon
It should be considered in only some application that needs to detect exactly number of the pressing.
Symptom: Button is pressed one, but Arduino code detects several times.
Cause: Due to mechanical and physical issues, the state of the button (or switch) is quickly toggled between LOW and HIGH several times
Solution: Debounce. See Arduino Button Debounce

lastchancename

CORRECTION: change thread title, "If digitalRead() works, but not as you expected"
There is no 'button' functionality other than the button library.
Inputs may need to operate the way they do for applications other than 'buttons', perhaps you might explain detecting state-change and debouncing.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

PerryBebbington

Hello IoT_hobbyist,

Excellent! This is a repeated frustration here, along with having 2 power supplies and not connecting the 0V from one to the other.
++Karma;

larryd

Maybe an image like this could be offered:





No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

IoT_hobbyist

CORRECTION: change thread title, "If digitalRead() works, but not as you expected"
There is no 'button' functionality other than the button library.
Inputs may need to operate the way they do for applications other than 'buttons', perhaps you might explain detecting state-change and debouncing.
Thank you for your correction.

You are absolutely correct in term of concept.
However, I would like to keep the title because It is familiar to newbie.

IoT_hobbyist

Hello IoT_hobbyist,

Excellent! This is a repeated frustration here, along with having 2 power supplies and not connecting the 0V from one to the other.
++Karma;

Thank you,

I will make another FAQ about two power supplies.

IoT_hobbyist


Go Up