Path: EDN Asia >> Design Ideas >> IC/Board/Systems Design >> Read multiple switches with one MCU input pin
IC/Board/Systems Design Share print

Read multiple switches with one MCU input pin

17 Jul 2015  | Kevin Fodor

Share this page with your friends

You determine the value when you press S1 by evaluating the voltage divider that RBIAS and RRFFMAX form:

Observe that when RADJ is at its maximum value and you press S1, it must produce a value less than the smallest value RADJ produces by itself to uniquely determine that you have pressed the switch. So the maximum effective resistance, REFFMAX, must produce a value less than the maximum low voltage, as the following equation shows:

Substituting and solving this equation for the switch resistance yields:

Using the spreadsheet to compute the switch resistance yields 1558Ω, and you can choose a nominal 1.5-kΩ resistor. This selection causes S1 to produce a range of 28 to 71 when you press it, depending on the potentiometer's position. Likewise, choosing the same value for S2 produces a range of 184 to 227. These ranges are bands of values that you can use to determine which switch you pressed regardless of the potentiometer's position. Although selecting symmetrical resistor values is not necessary, it minimises the number of calculations you need to perform and simplifies the design. Furthermore, selecting smaller series switch resistors opens the guard range between them and the potentiometer, which may be desirable if the resulting values are too close together. The microcontroller uses a small subroutine, Listing 1, to determine both switch positions and the potentiometer's setting.

Listing: Source code of design.

The limitation of this technique is that you cannot press more than one pushbutton at any time. In addition, the microcontroller can read the potentiometer's position only when you are not pressing any other pushbuttons. This example shows how to use two pushbuttons, but the number of pushbuttons can vary. Input ranges are available for as many as 10 pushbuttons and one potentiometer, all of which share the same input pin (figure 2). Although the computed ranges do not overlap and are unique, it is doubtful that your ADC hardware can reliably distinguish these bands under all circumstances. Choosing smaller resistor values keeps these bands farther apart, creating a larger guard range.

Figure 2: The circuit can have 10 pushbuttons and one potentiometer.

Using this technique with four pushbuttons and one potentiometer is well within reason. Experimenting with the spreadsheet helps make quick work of determining just the right series-resistor values for each switch and its output range.

About the author
Kevin Fodor contributed this article.

 First Page Previous Page 1 • 2

Want to more of this to be delivered to you for FREE?

Subscribe to EDN Asia alerts and receive the latest design ideas and product news in your inbox.

Got to make sure you're not a robot. Please enter the code displayed on the right.

Time to activate your subscription - it's easy!

We have sent an activate request to your registerd e-email. Simply click on the link to activate your subscription.

We're doing this to protect your privacy and ensure you successfully receive your e-mail alerts.

Add New Comment
Visitor (To avoid code verification, simply login or register with us. It is fast and free!)
*Verify code:
Tech Impact

Regional Roundup
Control this smart glass with the blink of an eye
K-Glass 2 detects users' eye movements to point the cursor to recognise computer icons or objects in the Internet, and uses winks for commands. The researchers call this interface the "i-Mouse."

GlobalFoundries extends grants to Singapore students
ARM, Tencent Games team up to improve mobile gaming

News | Products | Design Features | Regional Roundup | Tech Impact