Connecting 2-pin button

Hello all, I've seen lots ot tutorials explaining how to connect a button to Arduino and I've even played with some, but they always had 3 or 4 pins. Recently I've aquired these tasters and I don't really know how to connect them properly to Arduino since they've got only 2 pins. Suggestions anyone? Here's the picture:

Connect one side of the button to Gnd and the other side to an Arduino pin. Configure that pin as a digital input with pullup enabled:

pinMode(pinNumber, INPUT);
digitalWrite(pinNumber, HIGH);

then if the button is push-to-make, a digitalRead from that pin will return LOW when the button is pressed, HIGH when it is not pressed. If the pushbutton is press-to-break, this will be reversed.

2 Likes

AWESOME, I don't even need resistors. Thanks a bunch.

PS - I should have said don't use digital pin 0, 1 or 13. Any other pin will do.

Having a similar issue and I am very new to this. I have same type buttons/switches (Normally Open), though I want to connect 4 of these to a Teensy 2.0 board. What kind of connection would I need?

I have read some other postings and they say this:

ButtonA = 1pin to 10ohm resistor to ground + pin on board, 1 pin to 5V
ButtonB = repeat similar
ButtonC= repeat similar
ButtonD= repeat similar

Ideas?

ButtonA = 1pin to 10ohm resistor to ground + pin on board, 1 pin to 5V

10 "K" (10,000 ohm) resistor and this is OK...

naweston:
Having a similar issue and I am very new to this. I have same type buttons/switches (Normally Open), though I want to connect 4 of these to a Teensy 2.0 board. What kind of connection would I need?

I have read some other postings and they say this:

ButtonA = 1pin to 10ohm resistor to ground + pin on board, 1 pin to 5V
ButtonB = repeat similar
ButtonC= repeat similar
ButtonD= repeat similar

Ideas?

It's simpler to connect each button between ground and an Arduino pin and enable the internal pullup resistor, as I said before.

dc42:
It's simpler to connect each button between ground and an Arduino pin and enable the internal pullup resistor, as I said before.

So no physical resistor nor a lead to 5V, correct?

Just 1pin to I/O pin, 1pin to GRN?

That's correct. Do a digitalWrite(pin, HIGH) to each of the input pins, that will turn on the internal 20K pullup resistors on those pins.

dc42:
PS - I should have said don't use digital pin 0, 1 or 13. Any other pin will do.

Sorry for the bumping, I haven't been around, but why not 0 and 1?

Those are the internal serial port. This is the same port used when you upload sketches.

Technicaly they can be used but you would have to disconnect them every time you upload a sketch so its much easier as a beginner to avoid them if possible.

dc42:
Connect one side of the button to Gnd and the other side to an Arduino pin. Configure that pin as a digital input with pullup enabled:

pinMode(pinNumber, INPUT);
digitalWrite(pinNumber, HIGH);

then if the button is push-to-make, a digitalRead from that pin will return LOW when the button is pressed, HIGH when it is not pressed. If the pushbutton is press-to-break, this will be reversed.

Hi there, sorry for the bumping too, but I don't get why you get "reversed values" with the DigitalRead, by reversed I mean:

0 when the button is pressed
1 when the button is released

Thanks!

The input is "pulled" HIGH by the internal (or external) resistor) while the switch is open, therefore is a 1 (or HIGH or true). When the button is closed, the input is "pulled" to ground for a 0 (or LOW or false). The switch is said to be "active low".

groundfungus:
The input is "pulled" HIGH by the internal (or external) resistor) while the switch is open, therefore is a 1 (or HIGH or true). When the button is closed, the input is "pulled" to ground for a 0 (or LOW or false). The switch is said to be "active low".

Hi, thanks for the quick anwser, I think I get it now. This kind of swich is open while I'm pressing the button, right? and when I release the button the circuit is closed?