Reading out multiple buttons with a single ADC pin

Impedance_Voltage_divider.png

In this video I show you how to read out multiple buttons using only one ADC pin.

I hope this is helpful to all of you who have not enough I/O pins left or to those you want to control loads of switches!

 

The resistor value you will generally use will be 10k or more so you don't draw loads of current, forgot to mention that in the video :)

 

If you like it leave me a comment and give me a thumbs up on youtube ;)

https://www.youtube.com/watch?v=RPl_bNT5j4M

Still a nice idea

If I remember right, this principle is described in the book ‘Extreme NXT’.

Didn’t know that :slight_smile: Never

Didn’t know that :slight_smile: Never had an NXT, started off the hard way of trial and error :stuck_out_tongue:

A page I ran across some years back.

http://mientki.ruhosting.nl/data_www/pic/projects/pic_switch.html

It is called as a frame from the following page.
http://pic.flappie.nl/

While the pages are more generally slanted towards PICs and JAL, some of the hardware links should be fairly universal.

Nice idea, but…

It works in principle fine as long as only one button is pushed at a time.

If multiple buttons are pressed eithr by purpose or accident the measure result is not predictable since the whole resistor divider changes.

Just an important thing to consider.

The below method is ‘safer’ since by selecting the correct resistor values it should be possible to detect multiple buttons.

ScreenShot030.png

Awesome

I thought about this a while ago, never got round to doing it)can’t remember to be honest) nice job.

How many uses for multiple button press?

In embedded systems, the only time I can think of ever needing to detect multiple button presses is for going into diagnostic modes. If a diagnostic mode is not required then you can easily program out the incidence of multiple button presses as invalid response.

I think I prefer your circuit though.

I think this could be useful

I think this could be useful for implementing with small micros, its a different approach from the matrix keypad configuration typically used to reduce the number of pins used.  The number of pins a matrix keypads uses is at least 2*sqrt(#_of_buttons).

Tested?

Has this idea been tested in real life?

When suggesting the 10K value for each resistor has you taken in account the maximum recomended output impedance according to the selected microprocessor specification? A PIC processor (PICAXE also) recommend a maximum value of 2.5k (the impedance/ohm resistance) going to V+ (5 VDC). This is important in order to charge the internal measuring capasitor in the mircoprocessor wtihin the in the microprocessor specified timeframe.

Let me know if more explanation is required.

Note: The similar circuit that birdmum has linked to is using an analog comparator as measuring device which does not have the capacitor issue.

Anyone who maybe know better and disagree please comment on this.

Yep, you’re right. 10k may

Yep, you’re right. 10k may be a little much for the ADC.

Tested this with 1k resistors and it works a treat, but anyway depending on which button you press the impedance to VCC is going to exceed 2.5k when you press button 3 or higher.

Debouncing

To make things even more complicated, there is probably no way around that you will need to do some debouncing of the switch, just like it was digital input.

It takes, depending on the microprocessor, approximately up to 30 uS to make an analog conversion

In this example taken from this excelent article by Ganssle (http://www.ganssle.com/debouncing.htm) it can take up to 150 uS before the switch deactivate (or activate). 

debounceswitchc.jpg

So depending on when you program makes the convertion it might not be the right value (read: pressed switch) unless you read multiple times over several mS until you get values within acceptable ranges/zones. This goes for both activating and deactivating. It is easier to detect when deactivation because you will know that you should get a fairly stable 0V value on the input. It get more interesting when you need to detect the activating value. But that is just an exciting programming excercise.

Circuit 2

The advantage of this circuit is that it draws no current when no switches are activated. Otherwise my other comments apply to this circuit as well.