Pages: [1]   Go Down
Author Topic: Connecting 2-pin button  (Read 4108 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 215
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Full Member
***
Karma: 1
Posts: 215
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: September 28, 2011, 12:22:42 am by naweston » Logged

Topsham, Vermont USA
Online Online
Edison Member
*
Karma: 23
Posts: 1757
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Full Member
***
Karma: 1
Posts: 215
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 178
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: