0
\$\begingroup\$

Im trying to connect 8 buttons to Arduino Analog input. I found its good to use input shift registers. But with my very basic knowledge I end up with resistor ladder. But Im a bit confused with various sketches when I googled it. Some having same resistor values. Some using different values. In my case I dont need multiple buttons at a time. Only one button at a time.

Im thinking about using this sketch below.

enter image description here

But I really getting confused by the different values resistor sketch in another result. So which is the best suits in my case. Also please suggest a good value for resistor and pull down resistor.

This is another one I found to depend.

enter image description here

But there a confusion why there are two extra resistors. I imagine the 100k is pull-down. But what about the 2k.

In your suggestion which is best or any better sketch anyone can suggest?

\$\endgroup\$
2
\$\begingroup\$

I found its good to use input shift registers.

Not sure what that has to do with the rest of the question.

The point of the ladder is to produce various voltages spaced between Vcc and Ground. By pressing the appropriate switch you present the selected voltage to the micro to read and identify.

How you do that is pretty arbitrary and you can use whatever values you want within limits as long as the resultant voltages are distinct enough for the micro to separate. Limits being you don't want the resistance so high that you have noise issues, and don't want it so low you consume too much current.

Looking at the second circuit you can see that there is a total of 10K resistance in the ladder and eight switches. The designer set it up so that there is 0.5V between switches, presumably to make it easier to identify which switch is pressed when using a multimeter. (Since the micro doesn't care much). Either that or the designer just likes things nice and tidy.

As you suspect the 100K is there to pull the pin down when nothing is pressed and the 0.1uF is included to provide a little debounce.

Handling Simultaneous Button Presses

As you mentioned, this technique is fine if only one button will be pressed at one time. If you need to handle more than that you should consider using an R/2R network.

enter image description here

These networks are basically simple digital to analog convertors that encode the switch settings into unique analog values. Notice bit 0 on the left has the base level resistor and each subsequent switch has double the previous value.

The example shown above includes an op-amp but that produces a negative voltage proportional to the set switches.

The schematic below uses no active components. Output is zero when nothing is pressed. When SW8 is pressed it outputs half rail. All other switches are then encoded above half rail up to close to Vcc.

schematic

simulate this circuit – Schematic created using CircuitLab

DEBOUNCING

The issue with all these methods is debouncing. Switches bounce, that is, when pressing them or releasing them they make and break contact repeatedly until they settle in one mechanical state. As such it is very important for the monitoring software to watch the ADC value for a period to determine it has settled into a value before decoding said value as the switch setting.

\$\endgroup\$
  • \$\begingroup\$ That was seriously helpful.. thanks a lot for the bonus info too \$\endgroup\$ – Sandeep Thomas Sep 28 '17 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.