Pushbutton Confusion

I am confused... I want to add two simple pushbottons to my project and there are two million tutorials on how to add them out there - but each one seems to show it in a different way.

Some show the pushbutton simply connected to a digital pin and to GND, so two wires only with NO resistor used.

Other use a resistor - sometimes on the positive side, sometimes on the GND side.

Others show pushbuttons connected via THREE wires.

So I am quite confused now.

In my project, I am using short wires (~10cm) and I am initializing the two buttons (on digital pins 5 and 6 with

pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);

Each one is connected to it's digital pin and GND. No resitors used.

This seems to work fine. digitalRead(pin) gives 1 then if a button is NOT pressed and 0, if it is pressed.

So I used the most simple way to connect pushbuttons and it works fine. Why the need for additional resistors then? And why are many using THREE wire connections instead of two? I am quite confused :neutral_face:

If you have long wires, using external low value resistors can help mitigate noise problems.

pushbuttons connected via THREE wires

A pushbutton only has two contacts. How do you connect Three wires?

Not an expert here, but you don't need external resistors because you are using input pullup in software, so you are using internal resistors.
About the "3 wires", maybe the button had a led too, with the gnd connection in common for the button and the led, or it's a toggle switch (?)

Sure, I am aware that a pushbutton has two contacts only. What I was reffering to is this:

"3 Wires":

"2 Wires":

Method 1 (above) shows a pushbutton connected to 5V. GND and a pin.

Method 2 shows it connected to GND and a pin only.

That confuses me. What is the difference between both?

The "three wire" is a pushbutton circuit that uses the external pullup resistor. One end of the resistor is connected to 5V. Use pinMode(pin, INPUT)

The "two wire" uses the internal pullup resistor. Use pinMode(pin, INPUT_PULLUP)

There is also another circuit that uses a puldown resistor connect to GND rather than 5V.

It's how you configured your pin

pinMode(5, INPUT_PULLUP);

The _PULLUP tells the ATMega328 microcontroller to use the internal pull up resistor tied internally to pin 5. The resistor and red wire is physically inside the microcontroller. Therefore, no need to add it again.

Some idiots like to take advantage of the fact that while there are four terminals on a push button there are only two connections. There is a dead short between the left hand and right hand pair of contacts. I say idiots because this is a very confusing way of connecting things for people who don't know this.

In my not so humble opinion push button switches should always be wired across the diagonal, it doesn't matter what diagonal, either will do (but not both).

So when using relatively short wires (< 20cm) and INPUT_PULLUP I can get away with the simple "2 wire" method - one side of the button connected to a digital pin, the other one to GND - without additional resistor, right?

I believe Grumpy_Mike is pointing out your "2Wire" diagram is wired wrong. One wire should be connected to the top of the switch for it to work properly

For short wires, INPUT_PULLUP is OK

Best way, provided your wires between Arduino and button are short.

Long wires can pick up interference and the internal pull-up resistors are quite weak, which can potentially result in false button detections.

Also ok, and best if your wires are long.

Worst way. There is an increased risk of a damaging short-circuit if the wire from +V to the button gets accidentally detached and touches something.

Hello 2KBastler

Take a view here to clean-up the confusion how to connect a push button.

Ich wünsche einen geschmeidigen Tag und viel Spass beim Programmieren in C++.

Not quite.

The two wire example will work correctly, but it is a confusing configuration for beginners.

Also there is no need at all to use three connectors when you want to use a pull up ir pull down resistor. Just wire across the diagonal and add the appropriate pull resistor on the appropriate side.

Thanks Mike. You forced me to research that further. I remembered which pins were internally connected wrong. These two are internally connected.

More button switch info here