I hooked up one of the detent potentiometers to an Arduino Nano and took some readings. I thought that with 11 positions in a range from 0 to 1023 that they would most likely be evenly spaced apart. Not so! The lowest position gives a pretty solid 0 but the next position is around 14. So I used a table of threshold values to map the readings to index values from 0 to 10 (11 distinct values).

The program (sketch) is in the attachments. Here's a run starting from the top and turning the pot CCW and then back. The index is shown first followed by the value obtained from the A/D conversion.

The sample time for the readings is set at 100 ms. And yes, you can miss a stop if you turn the pot fast enough. Once in position, the readings turn out to be pretty steady varying maybe 2 or 3 values. I'm not sure if all of them will work this well or if my table of threshold values will hold up in all cases; I arrived at the values using the GRJ method of observation.

The good news is that these will work out for what I have in mind. I mounted the pot in a plastic box and ran a 6 foot cable to the Arduino for these tests. They will be useful for controls on a front panel.


Photos (1)
Files (1)

Another thing that I noticed about these pots is that the readings change as you lean toward the next stop position. While at rest, the values are steady with only slight variations. But just applying pressure against the stops will raise or lower the value significantly. They aren't going outside the range of values setup in the table and are not giving any false triggers so that seems to be okay.

These are just pots with mechanical stops and are subject to some wiggle room. My applications are not mission critical in that regard. So I think they're going to work out.

I'm guessing maybe the audio taper (or reverse taper), the A or C on this graph might have given you a better result with the steps.  I truthfully didn't think of what you experienced when you bought these.  I'm still a little confused about the wide range of values, what exactly does the circuit look like that's feeding the A/D?  Is there some loading we're not taking into account?  Maybe using a lower value pot would have minimized any loading effects.


Photos (1)

GRJ: You may be right about the different tapers. The low and high ends of these linear pots have a tighter range of values. It would be interesting to try the others just to see what comes out.

I'm satisfied that these will do the job. Just a bit of a surprise that the spacing is so uneven. I plan to check some of the others from the lot that I got from Mouser. I expect that they will behave in a similar fashion.

In thinking about this, I still don't understand the results you're getting.  Take the following circuit feeding the Arduino A/D input.  I would expect the results to be more consistent across the steps, and I'm truthfully confused as to why they wouldn't be.  The input impedance of the analog inputs on the Arduino are claimed to be in the many megohm range.

The arduino analogRead() function should return a value consistent across it's range relative to the input voltage.

Reads the value from the specified analog pin. Arduino boards contain a multichannel, 10-bit analog to digital converter. This means that it will map input voltages between 0 and the operating voltage(5V or 3.3V) into integer values between 0 and 1023. On an Arduino UNO, for example, this yields a resolution between readings of: 5 volts / 1024 units or, 0.0049 volts (4.9 mV) per unit.

What am I missing?


Photos (1)

You've got the circuit for the pot to Arduino connection just as I set it up. I took this from a YouTube video series but mine goes to a Nano instead of a Uno. Other than that it's identical.

So as I understand it, the pot acts as a voltage divider to feed the analog input between 0 to 5 volts. But it's a ratio kinda thing so it could produce the short range of values at the end points? Anyway, that's all there is to the circuit.


Photos (1)

I'd be interested in seeing the voltage values at each stop that are going into the Arduino.  I can't imagine why it's all over the map like that.  Maybe the switch with the resistors wasn't such a bad idea.

Could it be that the mechanical nature of the pot is what's throwing the values out of kilter? As I mentioned before, I have seen the readings (from analogRead) change just by applying pressure against the stop positions. So with the initial readings, which is what you are seeing in the program's output, the mechanical movement has not yet completed and it remains out of a settled state?

In other words, perhaps this is similar to switch bounce. It might give a more accurate reading after a short period of time has elapsed once there is an initial change that warrants further sampling. I could do that.

Still, you would think that the spacing of values would be more uniform than going from 0 at the low end to just 14 in the second position. It's a bit puzzling.

93 * 11 = 1023

This could be a mechanical effect from slop or backlash of the detent and possibly the wiper of the pot.  Have you checked the repeatability of the readings across several tests?

For comparison you could do a test with a regular 10K pot.  It is not critical to match the exact positions of these readings, only need enough points to draw curve similar to the one above. 

The DFRobot switch uses fixed resistors and should have better repeatability.  However this circuit cheats by driving the LEDs from the voltage divider.  This will introduce non-linearity to the output curve.  Also each LED sees a different input voltage/resistance.




penn station posted:

For comparison you could do a test with a regular 10K pot.  It is not critical to match the exact positions of these readings, only need enough points to draw curve similar to the one above.

Cam: I could get readings from a 10k pot. That would give a good x value. But the positioning would be ballpark and not very good for a y value. That's if I am understanding what you are proposing.

I have some other ideas. Let me try a few changes. I'll at least give you guys some more to look at.

I'd still like to see a set of voltage readings with 5V on the post and just a voltmeter on the output.  A set from either direction would be useful.

One thing you might want to do is loop on the read until the value settles and not just take the first value.  I have to believe something is off here, there would be no point in putting detents on the pot if it was that flaky!  I'm having a real problem with the voltage varying by a 10:1 ratio between stops on a linear taper pot, that makes no sense to me.  If the A/D is getting true values, I would expect maybe a 10-20% variance in the step sizes, but not what you're seeing!

Leo, I was just proposing that as a test.  The positions are not critical and not critical to be the same position in the other direction.  The idea is the get the shape of the curve.  If this is much better than the detent pot it would point to problems with the latter.


Can you do a simple bench test of one pot with just a voltmeter connected?  Use this diagram and just connect the voltmeter on the center wiper and ground and do a reading for each detent going up and going down.  I'm very curious what you're actually getting for voltage steps.

gunrunnerjohn posted:

Can you do a simple bench test of one pot with just a voltmeter connected?  Use this diagram and just connect the voltmeter on the center wiper and ground and do a reading for each detent going up and going down.  I'm very curious what you're actually getting for voltage steps.

That's my next plan of attack. I don't have a bench power supply to work from but I think I can manage to get the readings from the Arduino setup that I'm using. The 5 volts comes from the USB port. Stay tuned...

If you have two decent voltmeters, monitor both the 5V supply and the wiper voltage.  This will allow us to see if the supply voltage varies.  With a decent power supply, that might not be necessary.

With one meter I would connect one probe to GND so it is hands free.  Use the other probe to take a reading from the top and middle of the pot for each step.  You can do this while it is still connected to the arduino.  Then disconnect the wire to the analog input and do another run.  This will show the results in-circuit and the pot by itself.


I disconnected the wiper from the analog input pin and took the readings between that and ground. The voltage on the rails is 4.61 that's from the USB connection. Here are the values I got; I've only got one meter:

0 - 0.00
1 - 0.06
2 - 0.54
3 - 1.11
4 - 1.71
5 - 2.35
6 - 2.96
7 - 3.56
8 - 4.11
9 - 4.55
10 - 4.61

10 - 4.61
9 - 4.55
8 - 4.10
7 - 3.54
6 - 2.94
5 - 2.33
4 - 1.70
3 - 1.10
2 - 0.52
1 - 0.06
0 - 0.00

Pretty much the same in both directions.

I need to get some alligator clip probes! I'm beginning to grow a third arm!

In the middle of the pot, they look fine, but at the ends, it's kinda' ugly.  Obviously, not an ideal solution, I think I'd go with the rotary switch.   At least now I understand why the A/D was giving you such odd values, it was just doing what it was told!

leo detent pot voltage

What he said.  Looks great in the middle but the two stops on each end have such a small zone.  Sure, you can adjust the thresholds to "center" the thresholds to the compressed ends, but to each his own.  I like GRJ's idea of cutting your losses (in my opinion) and using a 1P10T rotary switch with 1-cent equal-value resistors in a ratiometric-potentiometer configuration as was suggested early on. 

Of course to beat the dead-horse, I still favor the idea of using a rotary-encoder switch with 3-resistors albeit being an incremental vs. absolute encoder as discussed earlier. 


Photos (1)

I have tweaked the threshold table to be more in line with the "mid-points" between the values that I'm getting in the resting state. Even with my rough guessing it's been fairly reliable in detecting the change of position. The top and bottom get a range of 6 values. The rest was a calculation.

int table [] = {
  6, 64, 180, 311, 448, 586, 721, 850, 962, 1017

Thanks, once again guys. An interesting discussion.

  -- Leo

One other thought on this. The big "reveal" for me was that you can use the A/D converters in this way at all. Like the rotary switch that Cam presented and the keypad from Adafruit, this is a great way to externally control a program without taking up much real estate. I'm planning to make use of this technique as best I can.

Add Reply

Likes (1)
OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653