Offline
Full Member
Karma: 1
Posts: 120
|
 |
« on: September 14, 2011, 03:38:32 am » |
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
Online
Faraday Member
Karma: 131
Posts: 4675
|
 |
« Reply #1 on: September 14, 2011, 03:44:15 am » |
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. http://www.eschertech.com
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 120
|
 |
« Reply #2 on: September 14, 2011, 04:28:01 am » |
AWESOME, I don't even need resistors. Thanks a bunch.
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Online
Faraday Member
Karma: 131
Posts: 4675
|
 |
« Reply #3 on: September 14, 2011, 05:05:47 am » |
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. http://www.eschertech.com
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #4 on: September 28, 2011, 12:19:05 am » |
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
Edison Member
Karma: 11
Posts: 1363
... in The Woods In Vermont
|
 |
« Reply #5 on: September 28, 2011, 01:36:52 am » |
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
|
|
|
|
|
United Kingdom
Online
Faraday Member
Karma: 131
Posts: 4675
|
 |
« Reply #6 on: September 28, 2011, 05:19:44 am » |
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. http://www.eschertech.com
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #7 on: September 28, 2011, 07:14:33 am » |
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
Online
Faraday Member
Karma: 131
Posts: 4675
|
 |
« Reply #8 on: September 28, 2011, 07:30:07 am » |
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. http://www.eschertech.com
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 120
|
 |
« Reply #9 on: January 29, 2012, 10:06:47 am » |
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
Full Member
Karma: 0
Posts: 178
Arduino rocks
|
 |
« Reply #10 on: January 29, 2012, 12:51:50 pm » |
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
|
|
|
|
|
|