Can I read 5 switches off of one pin?

I am trying to see if I can read 5, or moreswitches off of one pin on an arduino uno.

My thinking is to creat a "volt meter"of sorts, off of the botom side of the 50k ohm resistor.
So each time a different switch is pressed it will return a paticular voltage to the MCU, it will read it off of a adc pin, and I can haveit put out a result.

I.E. 2 volts +/- .1 means key x is pressed, do this.......Y....


imgur

Do you think this will work?

Again, I am going to pull the voltage off of where the Volt probe is located.

Yes, you can read 5, or more switches off of one pin on an arduino uno.

https://arduino-info.wikispaces.com/Keyboards-MultipleButtons

Some Liquid Crystal Displays, such as this one, use that technique to read the state of 5 buttons.

One disadvantage of using this technique, is that when several buttons are pressed at the same time, only one will be detected. The one highest up the ladder will take priority.

One disadvantage of using this technique, is that when several buttons are pressed at the same time, only one will be detected. The one highest up the ladder will take priority.

Not necessarily. See Multiple Buttons on 1 analog pin - Exhibition - Arduino Forum

Maderdash:
Do you think this will work?

Yes, you can do it that way.

The circuit drawing "BillHo" posted as the first picture is how the "LCD Keypad Shield" is handling the five buttons on the shield.

But there are several disadvantages:

  • slower button reading (digitalRead()=4µs, analogRead()>100µs time required)
  • only one button is allowed to be pressed at the same time, or you get wrong button readings
  • more complicated programming compared to digital buttons

So there is just one advantage: You need just one analog input to read button presses of 5 different buttons. All the rest is disadvantages.

Very nice.
Thank you.
I will not have speed issues, nor debounce issues.
There shouldn't be a problem with hitting multiple buttons at once.
I'm planning on pushing small relays or servos with this.

BillHo, and JohnLincoln, Thank you for your posts, I may change my circuit up to one of the ones you have posted.

:grin:

If you wanted even more and want to save analog pins, use a parallel to serial IC.

8 bit Parallel in to Serial Out IC

Can read a combination of buttons being pressed at once. Does use an extra component.

I don't mean to bother you, but have you got an example of what it would look like?

jurs:
But there are several disadvantages:

  • slower button reading (digitalRead()=4µs, analogRead()>100µs time required)
  • only one button is allowed to be pressed at the same time, or you get wrong button readings
  • more complicated programming compared to digital buttons

It's also more difficult to wake the processor from a button press while maintaining reliable button discrimination.

Here is the "challenge".

I am looking to create "base pedals" for a keyboard, that will activate servos on a real keyboard setup to press real keys on a keyboard.

But, I am looking to use a standard phone line chord for the wired connection.
So I am limited to 4 very thin wires to work with.

That is why I am looking to do Ll I can with very few pins. I think I will need to have 12 switches powering 6 servos.

(Each servo will press 2 keys on the keyboard).

I know this can be done through a PC, and Midi, and numerous other ways, but just work with me here.

And as far as the phone wire I am using the phone wire because it is very flexible and durable, and common in case it breaks. I am going to use the curly type.

I HATE to see analog used for something that's inherently digital! But, if you've got only 4 wires and no power on the switch-end, that might be the best solution for you.

I'd rather see a serial or [u]multiplex[/u] solution. (BTW - The Arduino's ATmega chip has only one analog-to-digital converter along with an internal analog-multiplexer so it can read multiple analog inputs.)

I am looking to create "base pedals" for a keyboard, that will activate servos on a real keyboard setup to press real keys on a keyboard...

...I know this can be done through a PC, and Midi, and numerous other ways, but just work with me here.

I also HATE to see something done mechanically that's inherently digital-electronic. :wink:

But, it's YOUR PROJECT and YOU are in charge!

P.S.
A servo might be too slow, and since your switches are digital (on/off) you probably don't need a servo. Have you tried that part of the project? ...I thinking solenoid. But, a solenoid would require a driver circuit, and a servo has the driver built-in.