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.

Post navigation

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

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.

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?

*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.

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.)

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 ;)

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).

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 :)

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!