How To: Multiple Buttons on 1 Analog Pin - Arduino Tutorial




Introduction: How To: Multiple Buttons on 1 Analog Pin - Arduino Tutorial

About: Arduino Tutorials by Team

The Arduino uno board has 12 availabe digital I/O pins and 6 analog input pins, sometimes, on complex or 'big' projects, we run out of digital pins. In this tutorial you will learn how to use multiple buttons on one analog pin.

For example, if you have 4 buttons, you will need 4 digital pins to read them. But, if you connect them all together, with different resistors, you can read them from only one analog pin!

Let's see how it works

Step 1: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • 4x button sw
  • 4x leds (yellow,red,blue,green)
  • 4x 330 Ohm (or 220Ohm) resistors
  • 1x 1K, 2K, 3K and 10K resistors

Step 2: How It Works

It's quite simple, every time a button is pressed, the Arduino receives an analog value from 0 to 1023. Depending resistance to each button this value changes. By this way we can recognize which button was pressed.

Now let's see how it works in practice!

Build the circuit above and program the Arduino with the following sketch. Bellow you will find the Codebender serial monitor, just press the connect button to start serial communication.

As you can see if no button is pressed the value obtained is 0. Now press the first button (with 1K resistor) and keep a notice with the value that you received. Keep going with all of them.

Mine values are:

  • 1st button: 1013
  • 2nd button:1004
  • 3rd button: 995
  • 4th button: 871

Tip: You can use as many buttons you want ;)

Step 3: The Circuit

Let's see how we can use these values to control some leds. Build the above circuit, the connections are pretty easy.

Step 4: The Code

Here's the code, embedded using Codebender!

You can make your own modifications to the code by clicking the "Edit" button.

Tip: Don't use absolute values, for example: instead 1013, use 1010 to 1015 ;)

Step 5: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use multiple buttons on only one analog pin!

I hope you liked this, let me know in the comments.
There will be more of them, so make sure to click Follow button!



    • Tiny Home Contest

      Tiny Home Contest
    • Fix It! Contest

      Fix It! Contest
    • Water Contest

      Water Contest

    22 Discussions


    7 months ago

    Thank you so much!

    What if I will connect it to 3.3v port?

    Very good! Thank you!


    2 years ago

    Thank you, I was looking for this.

    Just before I start, why does it have to be those high resistance values? can it be done with lower values , such as 220, 330, 470? What does the value in the Serial Monitor represent?

    1 reply

    Hello, yes you can. With serial monitor you can find analog value that arduino receive when a button is pressed.

    just the button that has the highest value will be considered the clicked button :D

    Sadly, no. Ohms law doesn't work this way. If you press buttons with 2 and 4 ohms the parallel resistance will be 1/(1/2+1/4) wich is equal to 1.(3) ohms. so the program will do nothing as the highest resistance that is coded is 1015 ohms

    You are mostly correct... While yes, the parallel resistance of pressing the 2 ohm and 4 ohm button simultaneously would create a 3 ohm resistance.

    The program definitely doesn't need to "do nothing" it is very easy to just add to the program to account for a 3 ohm load and turn on LED 1 & 2 accordingly.

    Allowing you to press any combination of buttons at one time... even all 4.

    This is actually a common practice, I just tore apart the control panel on a low end ink jet printer a few weeks back that had 3 buttons hooked up exactly like this.

    No, it is really 1.3 Ohm. The parallel resistance is always lower than the smallest member as the current can share paths. 1/(1/2+1/4)=1/(0.5+0.25)=1/0.75=1.3

    For a more accurate distinction between buttons, or a more accurate way of capturing multi-buttons, you may want to consider using an R-2R tree. See

    Very clever! thanks for sharing

    Yes!!! Very cool idea and blindingly simple = thanks for sharing!

    1 reply

    This is a very handy trick! Try swapping out the 3k with a 5k, then you would be able to pickup combinations as well... I think ?

    1 reply

    Hi! You can use different resistors if you want. For example, you can use 1K, 5K, 10K, 18K ;) You just need to find out the analog value that Arduino received every time you press the button through serial monitor (step 2).