Let's Make Robots!

Reading out multiple buttons with a single ADC pin


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 ;)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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). 

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.