Multiple Buttons/Switches on one ADC Input

Small microcontrollers are cheap and easy to use, but one problem they have is a shortage of IO pins (input output). If you have a lot of inputs (e.g. sensors, switches, buttons etc), and outputs then a larger (more expensive) microcontroller is often required.

There is a good way around this problem when there are a lot of switches or buttons to detect; an example is shown below with three push to make buttons:

multiple switches connected to one microcontroller pin ADC

Instead of connecting the buttons to separate digital input pins on the microcontroller, each button can instead be connected up to different value resistor as shown above, and the combined output connected to an ADC (analogue digital converter) pin on the microcontroller.

When no buttons are being pressed, the ADC pin sees 0 volts thanks to the pull down resistor. If the top button is pressed, a voltage divider is formed with R1=47K and R2=10K, so the ADC pin sees 0.877V. If the middle button is pressed, a voltage divider is formed with R1=10K and R2=10K, so the ADC pin sees 2.500V. And if the bottom button is pressed, a voltage divider is formed with R1=1K and R2=10K, so the ADC pin sees 4.540V. The ADC pin monitors the voltage and by comparing the detected voltage with the known values for each button, the microcontroller will know which button has been pressed.

This is an excellent technique to use for up to around 10 buttons. Just remember that if more than one button is likely to be pressed at the same time things get a lot more complicated – particularly when there are a lot of buttons.


Leave a Reply