Buttons pinout question!

Hi,
I know this is a noob question, but I am really confused.
is the 10k resistor really necessary for a button connected to an arduino board?
I have connected buttons all my life so far with only 2 pins, Digital and Ground, without the resistor, until I saw that everyone else on google were using 3 pins, Vcc, Gnd, and Digital with a 10k resistor.

I'm really confused.

You would need to show a picture of the example with 3 pins.
Using 2 pins is fine if one side of the switch goes to ground and the other is connected to an Arduino pin configured for input and with the pins internal pullup resistor enabled 'pinMode(switch,INPUT_PULLUP);' to prevent floating pins triggering randomly. To read the switch the logic is reversed from normal in that the switch pin will normally read HIGH but reads LOW when the button is pressed.

no, an external resistor is not necessary if you want to connect a button between an input and GND - You can connect the button between the input and GND, but then you need to use the internal pullup resistor (just write : pinMode(pin_number, INPUT_PULLUP) ), so that the input is HIGH when the button is released ..... or you can use an external pull-up resistor (between the input and VCC) .
If you don't do any of these, then the input will be in an undefined state when the button is not pressed and your sketch won't work as it should.

edit : oops, Riva was faster than me :wink:

Aka, a resistor is necessary for a normal button to work. But this can easily be a internal pull up or down resistor in the micro controller. And normal Arduinos have a build in pull up resistor so that saves you from connecting a resistor externally. :slight_smile:

I would suggest that the pushbutton in question had 2 connections to each contact, and that the 'third' connection was actually internally connected to one or other of the two connections you were expecting.

have connected buttons all my life so far with only 2 pins,

You must be either very young, or not had very reliable results or only used TTL which naturally floats high.

Most people new to electronics tend to think of switches as in the top drawing, where in digital circuits, most things are connected to either Vcc or GND, nothing in between, like the lower drawing.
switch.png

Read this for the full story:- Inputs

" only 2 pins"

Isn't that because a basic switch only has two pins? One side, and the other.

(An additional contact actually comprises an additional switch.)

ChrisTenone:
" only 2 pins"

Isn't that because a basic switch only has two pins? One side, and the other.

(An additional contact actually comprises an additional switch.)

You're forgetting double-throw switches.

That was one of the reasons for my parenthetical statement. A DT switch is really two switches with one side in common.