Button triggers by itself, or works backwards

  • Push button

Why it happens

  • No pull-up or pull-down resistor.
  • With INPUT_PULLUP, pressed reads LOW.
  • The button is turned 90°, so two joined legs are used.

How to fix it

  1. Use pinMode(pin, INPUT_PULLUP); and wire the button between the pin and GND.
  2. Then pressed is LOW.
  3. Use two legs that are diagonal to each other.
  4. For one press counted many times, add delay(30); after it changes.

It worked if: The Serial Monitor shows 1 released and 0 pressed, steady.

From how the part works. Explained from how the part works; not tried on a real circuit for this page.

Didn't help? Search another error or ask us.