Loading...
Pages: [1]   Go Down
Author Topic: which controller can i use to connect 15 buttons  (Read 473 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys sorry for stupid question

i have a task, connect to arduino 15 analog buttons, when button is pushed send info to USB

for me is interesting which controller i need to buy and how can i connect so many buttons?

Thank you very much
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 96
Posts: 6331
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some more detail would be useful.  What do you mean by "analog buttons"?

For regular on/off buttons, any Arduino with a USB-to-Serial adapter would do what you ask.  The Arduino UNO is the most common,
Logged

Offline Offline
Edison Member
*
Karma: 21
Posts: 1353
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Analog buttons"?  I assume by that you mean pushbuttons?
74HC165, parallel_in-serial_out shift register, "daisy-chain" two, each switch to '165 input; constantly read the shift register data.

Here's a link to someone who "got it" - http://arduino.cc/forum/index.php/topic,10069.0.html
Logged

Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do

CO, USA
Offline Offline
God Member
*****
Karma: 4
Posts: 706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's also the analog buttons method, which could easily accomodate 15 buttons -- even on 1 analog pin, with careful choice of resistors, I think.
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

0
Offline Offline
Tesla Member
***
Karma: 50
Posts: 6526
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the buttons are pushed only one at a time, you could use a multiplexer like below to input a single analog pin.

http://www.sparkfun.com/products/299
Logged

Why I like my 2005 rio yellow Honda S2000 with the top down, and more!
GOOGLE ADVANCED FORUM SEARCH BELOW!  
Go to:  http://www.google.com/advanced_search?hl=en
put in key search words,
use site or domain:  http://arduino.cc/forum
or in a google search box put key words site:http://arduino.cc/forum

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 16426
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If one at a time, can also wire them up like a 4x4 matrix, and connect to just 8 pins using the keypad library, no external hardware needed.
http://arduino.cc/playground/Code/Keypad
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Edison Member
*
Karma: 21
Posts: 1353
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh-ho, Analog buttons -- there you go.
So, I guess the only "controller" ilinsky needs is any Arduino, 15 resistors (I guess), and, as far as "sending info to USB" goes, serial.print (and don't press anymore than one button at a time.)
Logged

Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 16426
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have 18 digital I/O available outside of Rx/Tx that are commited to serial port in this case.  Use 15 of them:
D2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
(A0-A5 are also D14-D19)

Why resistors at all?  Use internal pullups on input pins, buttons close to ground.
Code:
// I'm totally winging it here, may need to check the Reference page for syntax on a couple of things...

byte D[15]; // declare 15 element array
D[ ] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // map the Dx pins into the array, D[0] represents D2 ... D[14] represents D16
int x;  // variable we'll use a bunch

void setup(){
for (x = 0; x<15; x=x+1){  // setup a loop to go from 0 to 14 to access the array elements
pinMode (D[x], INPUT);  // set the pins as inputs, recall: D[0] = D2
digitalWrite (D[x], HIGH);  // enables  internal pullup

Serial.begin(9600);  // library takes care of setting D0, D1 as needed
}  // end setup

void loop(){

for (int x =0; x<15; x=x+1){  // set to read D[0] to D[14],
    if (digitalRead (D[x]) == 0){  // is a button pushed?
    value = x; // store the array index (?) that was found low, i.e. button was pushed
 
// now act on the button that was pushed

    switch (value){ // use this to jump to the code for the button that was pushed
case 0:
// code for D2
Serial.println(" button  on D2 was pressed");
break;

case 1:
// code for D3
Serial.println(" button  on D3 was pressed");
break;

//etc

case 14:
//code for  D16
Serial.println(" button  on D16 was pressed");
break;
 
     } // end switch

   } // end if button pushed, go read the next one

} // end void loop

Give it a shot, see how it goes
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Edison Member
*
Karma: 21
Posts: 1353
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
"Why resistors at all?"
With the "Analog buttons" the 15 resistors effect 15 voltage levels to an Analog input pin (they're all different values tied HI and with contact each effects a different voltage there) - one pin versus many.

A straight digitalRead or a shift register data shift routine will probably go a lot faster though.
Logged

Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 16426
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Given that no other IO is specified, go the straightforward route: digitalReads of "[push]buttons" being Hi/Lo.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

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

Great, thank you guys for great reply. well yeah is my fault to call pushbutton as Analog haha
i will try to use matrix 4X4 i guess is the most easy solution
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 17
Posts: 3456
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
well yeah is my fault to call pushbutton as Analog haha

No, the problem is that pushbuttons are being called buttons.

Don
Logged

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

Thank you a lot, now i understand more less how it work, appriciate your help!
 

Have 18 digital I/O available outside of Rx/Tx that are commited to serial port in this case.  Use 15 of them:
D2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
(A0-A5 are also D14-D19)

Why resistors at all?  Use internal pullups on input pins, buttons close to ground.
Code:
// I'm totally winging it here, may need to check the Reference page for syntax on a couple of things...

byte D[15]; // declare 15 element array
D[ ] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // map the Dx pins into the array, D[0] represents D2 ... D[14] represents D16
int x;  // variable we'll use a bunch

void setup(){
for (x = 0; x<15; x=x+1){  // setup a loop to go from 0 to 14 to access the array elements
pinMode (D[x], INPUT);  // set the pins as inputs, recall: D[0] = D2
digitalWrite (D[x], HIGH);  // enables  internal pullup

Serial.begin(9600);  // library takes care of setting D0, D1 as needed
}  // end setup

void loop(){

for (int x =0; x<15; x=x+1){  // set to read D[0] to D[14],
    if (digitalRead (D[x]) == 0){  // is a button pushed?
    value = x; // store the array index (?) that was found low, i.e. button was pushed
 
// now act on the button that was pushed

    switch (value){ // use this to jump to the code for the button that was pushed
case 0:
// code for D2
Serial.println(" button  on D2 was pressed");
break;

case 1:
// code for D3
Serial.println(" button  on D3 was pressed");
break;

//etc

case 14:
//code for  D16
Serial.println(" button  on D16 was pressed");
break;
 
     } // end switch

   } // end if button pushed, go read the next one

} // end void loop

Give it a shot, see how it goes
Logged

Pages: [1]   Go Up
Print
 
Jump to: