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