I’m running the code found at http://arduino.cc/en/Tutorial/ButtonStateChange and am having an issue with almost every switch I try. I’m using several different momentary lever switches, of this style: http://www.superdroidrobots.com/images/TE-044-000.jpg. Whenever I press and hold the switch, it is supposed to not add another count until let go, but it streams hundreds of “presses” in the serial port. This has happened with 3 different momentary switches from different suppliers. What’s going on here? I’ve got one side of the switch to digital pin 2, the other side connected to 5v, and a 10K resistor between 5V and ground.
Edit: also tried it on other pins than digital 2 with same results
I've got one side of the switch to digital pin 2, the other side connected to 5v, and a 10K resistor between 5V and ground.
No that's not how you connect buttons. The resistor must be connected to the input pin and one side of the switch. Then the other end of the resistor and the other end of the switch go to ground and 5V.