Buttons on Digital Pins

I still don’t get exactly how this works. Could someone please explain?

Selenaut,

I feel as if I’ve come into the middle of a discussion, as I don’t have a clear understanding of what you “still don’t get”.

The usual approach is that you put a momentary switch between a DI pin and either Vcc or GND. You then provide a pull-up (if the switch is to ground) or a pull-down (if the switch is to Vcc) between the switch and the DI pin or use an internal pull-up or pull-down. When the switch is not pushed, the pull-up or pull-down provides the voltage seen by the DI. When the switch is pushed, the Vcc or GND is what the DI sees.

Also, you should read the material on "debounce’ on the Arduino site.

Happy Hunting,

Eric

Thanks for replying. Do you know if there are certain values of resistrs that are good for this job? Or could I add different valued resistors to a number of buttons and connect them all to one analog pin?

That can work. Microchip mentions the technique in one of their Hints and Tips books.

Okay, I guess I’m going with the analog. Seems I can get more inputs that way. (I need about ten buttons to do a project idea I was thinking about, and I really didn’t want to waste pins.)

Selenaut:
Okay, I guess I’m going with the analog. Seems I can get more inputs that way. (I need about ten buttons to do a project idea I was thinking about, and I really didn’t want to waste pins.)

The only problem with the analog solution is that you cannot register multiple buttons at once, if you don’t need multiple key presses then its a great solution.

Another solution that works even if you don’t have an analog input. http://www.atmel.com/dyn/resources/prod … oc2532.pdf

How about hooking them up to an [R-2R ladder, then to an analog pin?](Resistor ladder - Wikipedia)