Button output random ones

HI, I have put on a button from a kit with 4 legs in a breadboard and connected it on one leg to 5V second leg to gnd and third leg to pin 8 (I saw this in a video). Then I wrote code that reads the input of the button and prints it. in the beginning, it would print 0 as it should and if I pushed shortly it would print 1 like it should buttt when I pressed a little longer or out of the blue it would only print 1's. if I took out the cable which was connected to pin 6 it would only print 0 as expected... what do you think is the problem?
I connected it according to Arduino Tutorial 27: Understanding Pushbuttons and Pull Up and Pull Down Resistors - YouTube this video and tried also with the Arduino site way.
THANKS!!

btw I am using arduino uno and button from the kit are and they are not on the same column on the bred board

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components. Posting images:

Did you define your pin similar to this:

//closing the switch causes a LOW on the input pin.
// 5v——INPUT_PULLUP (20K)——Pin——[Switch]——GND
pinMode(myPin, INPUT_PULLUP);

Hi,
The failure with that YouTube video is the presenter did not point out that although the button has 4 pins, it only has two connections. 2 pins per switch connection.

When protoboarding them it is advisable to consider only diagonal two pins as switch connections, this way no matter how the button is oriented you will always have the opposite switch connections.

Tom.... :slight_smile:

@guym12

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

TomGeorge:
Hi,
The failure with that YouTube video is the presenter did not point out that although the button has 4 pins, it only has two connections. 2 pins per switch connection.

When protoboarding them it is advisable to consider only diagonal two pins as switch connections, this way no matter how the button is oriented you will always have the opposite switch connections.

Tom.... :slight_smile:

Actually always read the datasheet. Good habit to get into, and if you don't know the part number you
buzz out the switch with meter - another good habit to get into (in case you have the wrong part or wrong
datasheet).