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
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
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 (?)
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
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.