Stories. Questions. Different perspectives.
Browse WAURE
← Advice & Questions
Technology · Advice & Questions ·

Why does my Arduino button report changes when nobody is pressing it?

Technology category photographTechnology

Our tabletop quiz button keeps changing between zero and one while sitting untouched. A friend suggested ordering a better switch. I copied a sketch using INPUT, but I haven't compared the breadboard wiring with the example it came from.

Arduino's documentation explains that an open switch can leave an input floating unless a pull-up or pull-down establishes its state. It also distinguishes those arrangements from INPUT_PULLUP. Arduino's pin-mode explanation

This is an Arduino Uno learning circuit, with no mains equipment or moving mechanism attached. What should I understand about the input before replacing the button or adding code that ignores changing readings?

Discussion

5 community replies

Draw what is connected when the switch is open. The important question is what establishes the input's state at that moment. A sketch and a partly remembered wiring layout aren't enough to tell you whether the chosen input mode makes sense.

INPUT_PULLUP can be useful, but don't treat it as a magic word to insert into any circuit. In Arduino's pull-up arrangement, the input reads HIGH with the switch open and LOW when it closes to ground. The code's meaning of “pressed” must match the wiring.

Adding a delay to quiet the display could hide what you need to observe. First separate an unstable idle reading from multiple transitions during a real press. Those are different symptoms, even if both make the quiz counter annoying.

I'd rebuild the small example from its complete diagram with power disconnected, then compare its open and pressed states before reconnecting the quiz counter. Stay with the documented board and circuit rather than combining fragments from different tutorials.

Record those two expected states next to the sketch once the example is understood. Otherwise a later edit may assume one means pressed simply because that feels intuitive. A readable explanation of the wiring is more useful than an unexplained reversal in the condition.

Join the discussion

More in Technology