Go Down

Topic: which controller can i use to connect 15 buttons (Read 900 times) previous topic - next topic

ilinsky

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

johnwasser

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,
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Runaway Pancake

"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
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

justjed

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.
... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

zoomkat

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
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

CrossRoads

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
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.
Arduino for Teens available at Amazon.com.

Runaway Pancake

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.)
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

CrossRoads

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: [Select]

// 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
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.
Arduino for Teens available at Amazon.com.

Runaway Pancake

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.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

CrossRoads

Given that no other IO is specified, go the straightforward route: digitalReads of "[push]buttons" being Hi/Lo.
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.
Arduino for Teens available at Amazon.com.

ilinsky

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

floresta

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


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

Don

ilinsky

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: [Select]

// 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

Go Up