Transforming potentiometer output

I am trying to correct my potentiometer output curve. I did some graphs on excel to better explain myself. The blue graph is the original output. The orange one is what i am trying to achieve and the grey one is what i got from a map function(will not work for what i need). I need another way to transform the blue graph into the orange one. I found out that lookup tables might work for what i need, but i have no clue of how i should implement it. Could someone help me out on this one? I am a total noob at arduino so please explain things carefully otherwise i won't understand.

Thanks to all that help! This community is amazing

What kind of potentiometer do you use, how do you control it?

The graph looks like you could say if the value is < 200, just divide it by ten. Then use the map() function between 200 and 800. Then between 800 and 1000, just divide it by 10. This should give you something close to the 'ideal' curve.

If it doesn't, you'll need to show us your hookup, as well as the actual code you are running.

The Excel data already is or can be transformed into a lookup table. Post the document if you want help, don’t expect people to recreate the data.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

In your graph, vertical axis is analog count, horzontal is ? ? ? angle of rotation of pot?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How have you got your pot connected?
What part number does your pot have printed on it?

Thanks.. Tom.. :slight_smile:

Let's say Yorange = A x + B represnts the ideal line
Yblue = f(X) is the output function of the potentiometer

You want to swap from f(X) to A X + B. Firstly, calculate coef A and B, then it's straightforward to compare and match the 2 LUT, Yorange and Yblue.

Consider buying a linear potentiometer.

DrDiettrich:
What kind of potentiometer do you use, how do you control it?

I am using a slide potentiometer.

fredmorais:
I am using a slide potentiometer.

Your pot looks like it has large portions at each end of the linear travel, or large wiper area that causes your ends to be at zero ohms or max ohms before the wiper is at its extremes.
Over 20% at each end is basically constant resistance and you only have less than 60% active values.

It looks like that pot was made for a specific application, you may not be able to satisfactorily use software to linearize the response from 0 to 100% position.

3 separate map fuctions may help, but the change in resistance for the first and last 20% does not look much.
Can you post a table of the raw data please?

Tom... :slight_smile:

Looks like you could break up your blue curve into 7 segments or so..... and determine straight-line approximate equations for each segment. These segments could then be mapped to the target line.

TomGeorge:
Your pot looks like it has large portions at each end of the linear travel, or large wiper area that causes your ends to be at zero ohms or max ohms before the wiper is at its extremes.
Over 20% at each end is basically constant resistance and you only have less than 60% active values.

It looks like that pot was made for a specific application, you may not be able to satisfactorily use software to linearize the response from 0 to 100% position.

3 separate map fuctions may help, but the change in resistance for the first and last 20% does not look much.
Can you post a table of the raw data please?

Tom... :slight_smile:

Here it is. On the left is slide position in percentage and on the right the analog output

Southpark:
Looks like you could break up your blue curve into 7 segments or so..... and determine straight-line approximate equations for each segment. These segments could then be mapped to the target line.

What function could I use for that?

If the potentiometer is in regular use, the values will change over time.

Paul

fredmorais:
What function could I use for that?

Eg....for one section of your raw curve, you might have something like y = m.X + C for a segment --- equation to a straight line. The beginning of the segment starts at Y1,X1 .... and the end of the segment is at Y2, X2. This means the 'y' values for this segment will be from Y1 to Y2 over the horizontal axis range X1 to X2. 'C' is the y-intercept. And 'm' is the slope, or gradient, which is 'linear change in 'y' divided by linear change in X).

So as long as you look at your raw data along any particular raw segment, and approximate it with a straight-line equation y = m.X + C , then you'll have the straight line equation for it. You can then fiddle with that equation ...... eg change the gradient 'm' to match the slope of your 'target' line. And also change the offset 'C', so that every 'X' value that you put into the modified equation will result in a new 'y' value that gets close to the values on your 'target/preferred line'.

Also..... your original plot. When presenting a plot or figure..... it's necessary to indicate what that figure actually represents (ie. your plot)...... eg. state what the y-axis represents, and state what the x-axis represents. So far, we can only see a plot with those coloured lines, but you really should indicate how you obtained those raw plotted values. Eg..... the x-axis values..... what does '0' to '100' mean?

Hi,
Try this code, it is just a basic working of the map function for each of the three approximate linear areas.
It compiles and runs, but I don't have your pot.

int potValComp;
int potPin = A0;
int potVal;
int oldpotVal = -1;


void setup()
{
  Serial.begin(9600);
  pinMode(potPin, INPUT);
}

void loop()
{
  potVal = analogRead(potPin);

  if (potVal <= 44)
  {
    potValComp = map(potVal, 0, 44, 0, 255); // bottom 25% of pot remapped to 0 to 25% of 1023
  }
  if (potVal > 44 && potVal < 975)
  {
    potValComp = map(potVal, 45, 974, 255, 767); // 50% middle of pot remapped to 25% to 75%% of 1023
  }
  if (potVal >= 975 )
  {
    potValComp = map(potVal, 975, 1023, 767, 1023); // top 25% of pot remapped to 75% to 100%% of 1023
  }
  if (potVal != oldpotVal) // check and print if potVal has changed
  {
    Serial.print("potVal \t");
    Serial.print(potVal);
    Serial.print("\t potValComp \t");
    Serial.println(potValComp);
    oldpotVal = potVal;
  }
}

Anyone like to modify, feel free.
map function uses y = mx + c, but in integer mode.

As @Southpark has suggested, even using some maths may make a smoother resolution.

Tom... :slight_smile:

1 Like