Multiple pushbuttons - one digital input

Hi,

Im doing a project in school where i want to sense when people is having a seat at a bench i have build...

Does anyone know if it is possible to connect 6 pushbuttons (on/off) to one digital input somehow?

What i want is to sense each time one of the buttons is pressed.

Is there anyway to create a circuit like that?

Hope someone can help

Best regards

Anders

You can't sense which one, or how many have been pressed this way,
but you can sense if one has been pressed.
Just put them in Parallel:

GND --- BTN --- INPUT
|- BTN -|
|- BTN -|
|- BTN -|
|- BTN -|
|- BTN -|

Make sure to enable the internal pull-up resistor like this:

``````pinMode(PINNUMBER, INPUT);
digitalWrite(PINNUMBER, HIGH);
``````

I need to sense each one individually..

I have to use around 60 meters of wire to make it work if i give each button an input on the arduino, but it seams like there is no way around that..

60 metres of wire before you get to the Arduino?

That's a recipe for induced noise!

Why can't you place the Arduino at the bench, and send buffered serial signals?

Better still, why don't you use an analog pin, and get a little bit clever with some resistoers to encode the switch position?
(this almost certainly won't work if the Arduino is 60 metres from the bench!)

If you have to do this over a distance of 10m, I'd opt for a wireless solution, like Xbee. Each Xbee has 1 analog and 3 digital inputs (more actually, but I believe some are reserved for special purposes), so you could choose to use either:

On the buttons side:
1 Arduino + Xbee OR
1 Xbee with the analog resistor encoding idea OR
2 Xbee's with each button connected to a digital pin

and a arduino or PC and Xbee on the receiving side

You could probably use an RC timing circuit to control how long each push button stays on, if you need to use a digital pin.

If you can spare an analog pin rather than a digital one it is easy, don't know if that helps at all

Let me back up the idea that analog Input + a variety of resistors, each one being different for each button is much better

now let me scratch that idea out and back up the other, better idea of spending the extra bling bling and buying a pair of Xbee's (series 1 will do)... You will also need a second arduino board tho...

If you did not want to pay for two xbees and don't like the analog method, use 2 arduinos, one on each end of a wire. You can tie the switches to 1 arduino. It then sends all the signals down a wire using some a convenient protocol to your second arduino, which does something with the information.

If you use a RBBB under the bench, your cost is about (\$12+battery pack - say \$14, plus switches and some wire), which is pretty cheap, and much less than (\$22x2= \$44) for two xbees.

You really have two different problems:

1. you need to read six inputs without 6 I/0 pins
2. 60 meters is too long for any direct input method

The best solution to solve #1 is to use an "I2C expander". You connect several of them to I2C bus on Arduino (analog pins 4 & 5) and each will give you a number of extra I/O pins. You could have 8 inputs chip for as little as \$1 (breakout version will cost you slightly more).

However, even if you solve #1 60 meter distance is way to far for i2c bus. I2C bus has capacitance limit of 400pF and the longer wires you have the more power yo need to drive the bus at the nominal speed. I seriously doubt you can get anywhere near 60m without hitting this limit.

You need to have much slower communication channel between your endpoints. Perhaps 2400 bps serial connection will work. You will need to put on the other end second Arduino or a cheaper device with UART interface (like ATTiny2313).

If you have spare funds consider some sort of wireless or RF to deliver your serial communication instead of running wires.

Finally, if you really tight on money try to hack an old PS2 keyboard which Arduino could read. If you are lucky you can get not 6 but 10 x 6 button inputs at once.

I think we are all missing something here, he said he would need 60 meters of wire to wire up 6 switches to the arduino. To my mind that means the switches are not 60meters away but 60/6 = 10 meters away. I suppose he forgot the earth return otherwise that would make it 5 meters away.
With a common earth return (sorry ground), at 10 meters a good pull up resistor of say 680R at the Arduino end should see the problem cracked.
Yes you will need 6 inputs or a port expander if you want to sense each individual switch.

If you connect each push button up in parallel and then have a different resistor after each button then you can do an
to determine which button has been presses from what reading you get. Just use 'if' commands to do a certain thing on a certain value (you will have to use a range of values e.g. 320<x<340 because the values will not be exactly the same every time)

Obviously you can only do this if you have an analog pin free...

Btw what is the rest of your project, what have you used all of the other pins for?

Mowcius

One thing to consider is instead of using a digital pin, use an analog pin and a different resistor for each button, then you can detect which button was pushed. I'm using this technique on my step sequencer project and it's working great, except for my last button, which I can't figure out how to get around... but otherwise the concept is solid.

Would it be possible to use an resistor and capacitor in series to differentiate which switch is pushed? In the same vein as using a resistor and an analog pin. Instead of measuring the voltage you would measure the length of time the capacitor takes to discharge.

Maybe something like this:

I am new to this stuff so I could be completely off my rocker. If R3>>R5 then when the button is pressed C1 should discharge through the digital pin. This should take a consistent time. The time it takes to discharge would give you which button was pressed. (Now that I look at it R1 and R2 might not be needed) Any thoughts? (other than that I am nuts...)

-Andy

Presumably with the project being something to do with a bench, if you did this with a capacitor then it would just stay powered slightly longer than the time someone sat on it...

Anyone noticed that he hasn't sent anything back, do you think he is actually reading what we have put?

Another thought is that can more than 1 of the buttons be depressed at the same time? If they can then the ideas with resistors etc would not work...

Mowcius

Hi all,