# Multiple Buttons And A Pot On one pin

[Kevin Fodor] shares his method of reading multiple inputs on one pin of a microcontroller. The analog to digital convert function of the microcontroller is used to read a potentiometer but with some careful calculations a resistor network can be built into the circuit that provides a unique voltage value for each button pushed. The only real drawback is that the system cannot read multiple button presses at the same time. Theoretically up to ten momentary push buttons can be used but [Kevin] estimates that only four plus the potentiometer will work reliably.

[Thanks Charper]

## 24 thoughts on “Multiple Buttons And A Pot On one pin”

1. atrain says:

Heres a better way of doing it:

Use an R-2R network, you can have any number of switches, limited to the accuracy of the ADC and tolerance of the resistors. It also allows multiple button presses etc.

Eg: One switch gives 1/2 Vref, one switch 1/4Vref, both give 3/4 Vref, very easy to calculate any switch combination, and every combination of switch is independent.

For simpler uControllers, you can use a mux and get 2^(n-1) inputs for every n pins used. (n-1 address lines, 1 data line for the value of the selected switch.) This method is better for uControllers without ADC, or if you want to use less math for faster code.

2. jean says:

That’s silly. Not only because this thing is around since earth was created, but because it’s like building houses with duct tape. If you manage to do such an effort to save pins, then you can go wild for a contact grid. As a side note: as a previous commenter stated, using a so-called “resistor ladder” it could be possible to detect simultaneous presses of a greater number of buttons; how can it be that you aren’t capable of filternig off these inaccuracies?

3. Well, this is about as close to “news” as TMZ.

4. *shocked* I’m surprised this one got trolled so bad. I didn’t come up with this circuit, but I was the one that forwarded it to HAD.

The resistor ladder is certainly a better way to read multiple buttons with an a/d (if an a/d is your preferred method for digital IO), but it doesn’t allow you to also read off a potentiometer input. Either way, I thought this was a hack in the true spirit of this site.

Here’s how I imagine it going: Some guy was probably using a real microcontroller in a real circuit to read a potentiometer. At the last minute management wanted to add some pushbuttons or downsize the uC package for cost. Instead of throwing his hands up in the air and walking away, the engineer bit down and found a solution.

5. TheCitySpiders says:

@Charper exactly the point i was going to make.
it is a good little Hack to add a static input to an A/D circuit with only that as an available input.

6. atrain says:

Actually, this is pretty cool, now that I’ve re-read it. This circuit can read both the potentiometer as well as the switches, at the same time. (I though the pot was there for adjustment or something – didn’t read it properly the first time.) Neat trick!

I bet you could still do some kind of R-2R style thing and still read the switches + pot independently. Eg: Switch 1, 2 are 1/2 Vref and 1/4 Vref, then the pot has a range of 0 to 1/8 Vref. Use math to subtract the value of switches, multiply by 8, and you’ve got your pot reading. (Of course, it would significantly reduce accuracy.)

7. Alexander Rossie says:

Pretty sure Moses had one of these on his stick. R-2R this shit and have done with it.

8. Reggie says:

I’ve seen arduino posts get trolled way worse than this. Most of the comments above are constructive in so much they point out how to go about doing it better, with refinements to what it can achieve.

I’ve had 8 buttons on a resistor ladder, which as has been noted gives you multiple button presses, if you use one of the buttons as a shift key you effectively have 14 functions/buttons at your disposal, all for one pin :D then you can put that pot on its own pin and have done with it ;)

9. Reggie says:

Quote from the first paragraph of the actual article: “The circuit in this Design Idea provides a way to convey mixed analog and digital inputs into a microcontroller using one input pin”

nothing to do with being hard pressed on space/costs by a boss anywhere. so might’ve been better if it had been complete, even the OP acknowledges that it lacked the multiple press detection option.

10. Whatnot says:

@Alexander Rossie That was funny :) (and probably true!)

11. With two buttons and a pot you can red multiple button presses.

When both button are press, it makes a specific voltage on the ADC. ex 3,4V

When you turn the pot, you will get that same specific value 3,4V but you filter it and never take it in consideration.

The moment you read 3,4V you will know that both button are press. When you read 3.3V then 3.5V you know the pot is been turn.

You can not press 2 button at the same time of turning the pot. That will not work with multiple button like the article say it.

12. Chris says:

This method is used by auto-manufacturers regularly.

I’ve seen this used in door-lock, window, sunroof switches, etc.

I’ve worked on a number of test systems that are used to check these type of switches.

13. @Chris

Wow, really!?!? I would think an automotive environment would be too harsh (EMI-wise) to use analog-based controls. That actually seems pretty scary to me.

14. Natrix says:

That’s a hack. One of the best ways to read many switches using a minimal of pins is by using a matrix. Most cell phone keyboards these days use this method.

15. Chris says:

@Charper

An example would be the new VW Polo.

The electric windows are controlled by a slave ECU fitted in each door. The window switch has five positions (Up, down, one-touch, etc), as well as illumination. This is all connected to the slave ECU by four/five wires.

The biggest culprit for EMI is the alternator and the HV electrical distribution system. Modern cars are well engineered to reduce the EMI fed back into the system.

Higher voltages, increase currents on the analogue systems reduce the affects of EMI; or increases the signal to noise ratio.

One diagram I have is for the sunroof switch. It uses a R-2R network to give ten posible switch positions. The sunroof ECU (slave) converts these values and sends them to the body control module (BCM).

16. Ren says:

I like it!
So there!

17. Eugene says:

From the article and discussion everyone is overlooking the error in the schematic and it is implied that the wiper of the pot is connected to the junction of the 2 switches.

18. sean says:

I remember about 20 years ago, long before usb joysticks, my friend and I put together a digital arcade joystick for a PC that used a resistor ladder and plugged into the old joystick analog ports. I think we could only get 4 inputs reliably differentiated on the port, so with the x & y & and two original digital inputs, we managed 10 inputs. That was enough for 4 directions and the 6 buttons needed for street fighter :)

19. ejonesss says:

remember the old vcr remotes from the 80’s where you had a long wire to the vcr?

remember the old hamlin slider boxes provided by the cable co?

both used resistors to do their work.

20. therian says:

If you really cheap that save on AD also by using capacitor and measuring charging time

21. Vaevictus says:

Seems everyone ‘fixing’ the buttons and skipping the pot. If you only had one pin, AND needed a pot and multiple buttons, this would work and I’m not sure your ladder would.

If there was a good way to prevent the invalid double button press, perhaps it’d be more usable.

It’s a decent enough hack for one pin, a pot and two buttons.

22. George says:

Sorry for bothering.
I am having a problem and I’m novice….
I want to send two signals (DC), from two buttons. From one side to another. The problem is that I have only one single cable to do that (plus ground). Is it possible to use this circuit from one side and sent it to the other without the use of a adc-dac? What circuit should I put to the other side to split them again?
P.S.: The buttons are pressed one at a time only!
Thanks!

23. MarcoLinux1998 says:

@ejonesss; lol. I remember those wired remote controls.

About the project: over time, switches aquire some resistence (dirt maybe?) adding to total resistence. The circuit starts to misbehave.

Wired RC Nightmare: You press stop, the vcr starts recording! :-). Please dont use this solution in serious projects (car, plane, etc).

This site uses Akismet to reduce spam. Learn how your comment data is processed.