will be read-only starting December 31st, 2018. For more info pleae look at this Forum Post


  created 02 Jan 2009 V 0.1

A library to connect more than 1 switch to a single Arduino analgue pin. Can pass a callback function (function pointer) to the constructor AnalogButtons, which gets called when a button event occurs (normal push down or hold down which can be configured for each button separately).

Heres the comments from the top of the source files.

Connect more than one button to a single analog pin, register a call-back function.which gets called when a button is pressed or held down for the defined number of seconds. Includes software key debouncing which may need to be adjusted, the the second argument to AnalogButtons class. Define the ANALOG_PIN in the constructor of AnalogButtons.

 The circuit:

5 buttons, 1 side of all buttons connected together to +5V. The other side of each button is connected via a different value resister (tested with) 1k, 2k5, 5k8, 10k, 18k to one side of a 100k resister which is in turn connected to GND. At the point where all the different resisters are joined you make a connection to your analog input. Basicly a different voltage divider is setup depending upon which button is pressed. You have to configure the Buttons Hi/Low values, see the comments in example code below and the AnalogButtons::configure(ANALOG_PIN) function.

More or less than 5 buttons could be added, just pick different values of the resister sot hat all buttons have different values which arn't too close in size.

I'm not sure what happens when Arduino is powered from batteries and Power V drops below V5.

by Neil DUdman and everyone who's ever used Arduino


AnalogButtons is a library for the Arduino.

It is created to help Hardware Abstraction, and readability of code. Making it childs play to use multiply buttons on a single analog pin and hiding how everything is managed. See the example in the library

Download, install and import

Download here:

Put the AnalogButtons folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library->Button".
Once the library is imported, an '#include <AnalogButtons.h>' line will appear at the top of your Sketch. Better still open the example provide in the library which should also appear in the Examples menu under AnalogButtons, it all should be simple and explained in the code.

I was able to compile past the WProgram.h error by changing the offending line in the mentioned headr file to this include instead:

#if defined(ARDUINO) && ARDUINO >= 100
      #include "Arduino.h"
      #include "WProgram.h"

Errors: In Ubuntu, and Arduino IDE there is a error in lijne 34 of AnalogButtons.h when declare:

  1. include <WProgram.h>

This program don't exist in the .ZIP file... (My apologizes because I post it here, I can't find where to post a BUG report or email to the author)