Go Down

Topic: Connecting 2-pin button (Read 5644 times) previous topic - next topic

kustom

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:


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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

kustom

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

dc42

PS - I should have said don't use digital pin 0, 1 or 13. Any other pin will do.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

naweston

#4
Sep 28, 2011, 07:19 am Last Edit: Sep 28, 2011, 07:22 am by naweston Reason: 1
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?

terryking228

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


10 "K"  (10,000 ohm) resistor and this is OK...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

dc42


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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

naweston



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?

dc42

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.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

kustom


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?

Goofballtech

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.

Go Up