Electronic – arduino – Connected 2-Pin Button switching randomly from LOW to HIGH

arduino

I got this ordinary 2-pin push button and now I'm trying to read its state.
Basically I want to turn a LED on and off.

My board is an Arduino Uno and the button is connected to GND and Digital Pin 2.
Also Pin 2 is configured as INPUT_PULLUP.
I followed the instructions in this tutorial.

My issues:

  • digitalRead(2) returns randomly LOW and HIGH
  • It seems like there's no pullup resistor configured even though it's definitely in the code
  • When I take the button in my hands and touch some parts it seems to work?

Questions:

  • The button is connected to GND. There are also other components connected to the same GND. Could there be too much connected to GND?
  • Do you have any ideas what I did wrong?
  • Could my Arduino be broken/fried?

Update:

Here is the datasheet for the button I bought.

Best Answer

The trouble may well be in the switch itself since it's not designed for the low-current switching your circuit needs, and is designed to switch fairly high voltages and currents.

In normal use those kinds of switches generate arcs when the contacts open and/or bounce, and those arcs blast off non-conducting films which can otherwise accumulate on the contacts and cause trouble.

The problem is that the low voltage and current levels you're trying to switch just don't have the power to blast off all of the non-conducting film that can build up on the contacts, which will leave you with intermittent contacts and the problems you're experiencing.

Instead of exercising the switch, try shorting across the pins on the Arduino with a clip lead or something and, if you get reliable operation, the switch will more than likely be the problem.