Arduino Potentiometer

Hi Everybody,
I hope I am writing in the right place.

I am really having some problems with a project that was supposed to be quite easy.

I bought a potentiometer and I wanted to read the values coming from it with the arduino.

This is the potentiometer I have: http://uk.rs-online.com/web/p/products/2499345/?grossPrice=Y&cm_mmc=UK-PLA-_-google-_-PLA_UK_EN_Passive_Components-_-Variable_Resistors&mkwid=s6GCpfdUw_dc|pcrid|88057073043|pkw||pmt||prd|2499345&gclid=Cj0KEQjw9r7JBRCj37PlltTskaMBEiQAKTzTfI-ziXWqFisFOMG0hM-K9pH9yulR1SfEJD-mzFCFyKsaAorp8P8HAQ

And this is how I wired it:

This is the sketch I was trying to play with:

int const potPin = A0;
int potVal;
int participantRes;

void setup() {
Serial.begin(9600);
}

void loop() {

potVal = analogRead(potPin);
//Serial.print("potVal: ");
Serial.println(potVal);

//participantRes = map(potVal, 215, 1024, 0, 100);
//Serial.println(" , partRes: ");
//Serial.println(participantRes);

}

Now, if I open the serial monitor, I can read the values coming from the potentiometer. The problem is that the readings look really unprecise. If I move the potentiometer starting from the bottom, I get a reading that goes from ~176 to ~1020.

If I try and map the readings so that the values go from 0 to 100 it does work in a way: the readings go from ~0 to ~99

The problem is that in both cases the values don't change in a linear way.
That is: say that I place the knob at the bottom of the potentiometer. Then I started moving it. The value goes almost immediately to ~30. Then if I keep moving, it moves very slowly between 30 and 50. That is, I can move it a lot and the values change very little. Then, all of a sudden, the value starts going to 60-70-80-90....

If I don't map the values, I get something even more clear. You can see that the value goes to 300, then all of a sudden jumps like crazy. If do a linear plot in excel it looks really crazy, jumping up and down.

I tried to move the knob very slowly, and this is what happens:

Note: at the beginning I hadn't used any resistance. But I have the impression that using a 10K resistance does make things a bit better. But anyway, I really don't understand much about resistance and this kind of stuff. Also, the potentiometer becomes really hot after a little while...

Does anybody have any advice? Why the reading is so crazy ??

Thank you in advance for any help

You connected it wrong. That's what happens when you try to guess the connections.

??? What is it connected wrong? I tried to look at the technical information of the potentiometer, but I did not understand anything. I asked help to an engineer, and he was even more clueless than me (forgive me, I don't have much background in these things...I am a psychologist, just trying to learn...)

Use a DVM to test the potentiometer for function and linearity.

.

"are well suited to high precision audio applications"
That says to me audio taper, not linear taper.

This site confirms it:
Potentiometer Type = Logarithmic

http://www.mercateo.co.uk/p/2794E-249(2d)9345/Alps_RS60N_Series_Logarithmic_Slide_Potentiometer_with_a_18_5_x_1_5_mm_Dia_Shaft_10k_20_0_25W_Solder_Lug.html?ViewName=live_gb&switchToCountry=gb&chooseGeo=true

The link says it is Logarithmic.

.

OH NO !! So, this means that the value increases logaritmically? There is no way to get linear values?
That is: I bought the wrong thing !?!? =/
I would say that this is what happens when a Psychologist tries to do electronic stuff Q__Q

Could anybody suggest me a linear potentiometer that would work with the arduino??

Thank you all for your replies by the way, I appreciate...

If you bought it for a linear application, you are out of luck.

You could use a lookup table, but the real answer is to buy the correct part.

.

Thank you =( that's a sad news, but I appreciate the help.

I will just buy a new one. Do you know a good one I could buy?

I wanted to buy this at the beginning:https://www.amazon.co.uk/DaoRier-Output-Potentiometer-Arduino-Electronic/dp/B06W5CNRX5/ref=sr_1_2?ie=UTF8&qid=1496335873&sr=8-2&keywords=linear+slide+potentiometer

but it takes 1 month to ship. Also, in a week I will move to Italy and I think they don't deliver to Ita...

You need one with a linear taper.
I am installing these on a board for a project.

The B in PTB indicates linear taper.
There are single and dual versions, with 60 and 100mm of slide travel.
I designed the PCB for the 60mm dual version, but am only installing single versions for now (customer request).

Great, thank you so much.
Just one question: what does it mean single or dual? I assume you are referring to the Fader Type, but I don't know what that is.

I'm searching online...for what I understand I can use a single...all I need to do is to get a value of 0 if the potentiometer is at the bottom and then to linearly increase to 100 if I move it to the top...

If you think about it the two ends of the track must be at opposite ends of the pot.

The wiper happens to be at one end. If in doubt get out the multimeter and check:

"check twice, buy once"...

dual is two-gang pot for stereo audio use.

"dual is two-gang pot for stereo audio use."
Or two linear pots for whatever control you are using them for, perhaps motor positioning, perhaps something else.

There are two separate sets of 3 pins for the dual pot.

"all I need to do is to get a value of 0 if the potentiometer is at the bottom and then to linearly increase to 100 if I move it to the top..."

byte slidePotValue = analogRead(A)/10; // result is 0 to 102. For when you want, you know, a little more:

"Nigel Tufnel: (pointing to knobs on guitar amplifier) The numbers all go to eleven. Look, right across the board, eleven, eleven, eleven and...

Marty DiBergi: Oh, I see. And most amps go up to ten?

Nigel Tufnel: Exactly.

Marty DiBergi: Does that mean it's louder? Is it any louder?

Nigel Tufnel: Well, it's one louder, isn't it? It's not ten. You see, most blokes, you know, will be playing at ten. You're on ten here, all the way up, all the way up, all the way up, you're on ten on your guitar. Where can you go from there? Where?

Marty DiBergi: I don't know.

Nigel Tufnel: Nowhere. Exactly. What we do is, if we need that extra push over the cliff, you know what we do?

Marty DiBergi: Put it up to eleven.

Nigel Tufnel: Eleven. Exactly. One louder.

Marty DiBergi: Why don't you just make ten louder and make ten be the top number and make that a little louder?

Nigel Tufnel: [pause] These go to eleven."

Quote from "This is Spinal Tap"

I guess the orange wire is 5volt, and the red is analogue in.
Try that with your log pot and see if you get a log curve before you connect a new lin pot.
Connecting a pot wrong could burn out the tracks inside.
Leo..

Great, I will try tomorrow morning.

GUYS, THANK YOU EVERYBODY, REALLY!

#CrossRoads, I loved that quote XD Anyway, I have to use it for an experiment. I will try and induce an illusion on some participants.

To do so, I will have to do a particular stimulation on them (just something hand delivered). During this stimulation, I want them to rate if they are experiencing the illusion and how much. So, if they start feeling the illusion they should start moving the knob up. The more they feel it, the more they should move it. Then I stop stimulating and they will keep rating how much they feel it until it goes back to 0.

Obviously, the value from 0 to 100 is arbitrary. I guess I could even have it going from 0 to 1000.

Anyway, it should not be that difficult. All I need is to record the values from the potentiometer. Then, actually, I would also like to write a .xls or txt output, but that's a problem for an other day ^^ I will study it once I can set up the potentiometer correctly.

By the way, one last question: do you think I need to use a resistance?

Gluce:
By the way, one last question: do you think I need to use a resistance?

No, you don't need a resistor. The pot is the resistor.
But... a resistor between 5volt and pot might have protected the pot if you had connected it wrong.

Attached is a 0-100% (101values) pot code I wrote, to play with.
Set serial monitor or plotter window to 115200 baud (as in the sketch). 9600 (default) is a bit slooow for this.
Leo..

// converts the position of a 10k lin(B) pot to 0-100%
// pot connected to A0, 5volt and ground

int rawValue;
int oldValue;
byte potPercentage;
byte oldPercentage;

void setup() {
  Serial.begin(115200); // set serial monitor to this baud rate, or change the value
}

void loop() {
  // read input twice
  rawValue = analogRead(A0);
  rawValue = analogRead(A0); // double read
  // ignore bad hop-on region of a pot by removing 8 values at both extremes
  rawValue = constrain(rawValue, 8, 1015);
  // add some deadband
  if (rawValue < (oldValue - 4) || rawValue > (oldValue + 4)) {
    oldValue = rawValue;
    // convert to percentage
    potPercentage = map(oldValue, 8, 1008, 0, 100);
    // Only print if %value changes
    if (oldPercentage != potPercentage) {
      Serial.print("Pot percentage is: ");
      Serial.print(potPercentage);
      Serial.println(" %");
      oldPercentage = potPercentage;
    }
  }
}

larryd:
Use a DVM to test the potentiometer for function and linearity.

.

I didn't see this explained explicitly, so here is the procedure.

Put your multimeter into an appropriate resistance scale to measure the full resistance of the pot, then measure pairs of contacts until you find the pair that has a constant resistance no matter where the slider is moved to. That pair is the endpoints of the pot, and the 3rd contact is the wiper.

Hi,
Where have all the images gone??????

A lot to be said for attaching and copy image address.

The entire thread of this post is ruined....

Tom...... :o :o :o :o :o

OH NO,
I am really sorry.

So, I have updates:

  1. I managed to get the log pot working. It was true, the way I connected it was wrong. Once I connected it correctly the values looked right...but still logarithmic obviously.

  2. I've just got the Linear Pot and it works. Everything looks good now.

So, I am having a problem with my computer and also don't have too much time.

I will post new pictures and show how I connected it and what the values look like.

In the meanwhile: thank you everybody once again for helping me.