Analogin Pot value inaccuracy

Hi,

I hooked 3 pots(100k each) to pins (A0, A1, A2) in my Arduino UNO (Rev 3).
I want to map() each pot value to a LCD. I'm using the 3-wire (595 shift register) with the lcd.
The problem is I got very messy readings from the pots. Sometimes in the middle position of pot A1 the LCD is showing 987...I never get 0 - 255 exactly.
Here part of my code

void loop ()
{
  
   iLCD.home ();
 currentColorValueRed =  analogRead(redPotPin);
  delay(2);
  currentColorValueBlue = analogRead(bluePotPin);
  delay(2);
  currentColorValueGreen = analogRead(greenPotPin);
  delay(2);
  
 
 
  iLCD.print("R:");
  iLCD.print(map(currentColorValueRed, 0, 1023, 0, 255 ));
  iLCD.setCursor(5, 0);
  iLCD.print("G:");
  iLCD.print(map(currentColorValueGreen, 0, 1023, 0, 255 ));
  iLCD.setCursor(10, 0);
  iLCD.print("B:");
  iLCD.print(map(currentColorValueBlue, 0, 1023, 0, 255 ));
}

You need to look at smoothing the value. Check the Arduino web site for examples. Basically to take a certain number of samples and then average them. Not sure how many you need. Fewer will be quicker but less actuate and more will be slower and more accurate. It doesn't matter to much about that for most applications i've had 8/10.. more pots connected to an Uno using multiplexing and smoothing with no real noticeable delay.

EVP:
You need to look at smoothing the value. Check the Arduino web site for examples. Basically to take a certain number of samples and then average them. Not sure how many you need. Fewer will be quicker but less actuate and more will be slower and more accurate. It doesn't matter to much about that for most applications i've had 8/10.. more pots connected to an Uno using multiplexing and smoothing with no real noticeable delay.

I'd like to use 0-255 range since my goal is to control a RGB LED. (each pot corresponds to a color value R, G, B). The strange behavior is getting 001 or 0041 instead of 0 or random numbers wher it shoulbe be 255... Maybe it's a LCD problem since it print 789 or 999 that's a value out of the map() range??

One thing you could change is your pot values. Arduino analog input pins are designed to be driven by a source resistance of 10,000 ohms or less. Your 100K ohm pots are sure to give unstable conversation values.

Lefty

Could it be something as simple as LCD artefacts? Your using setCursor to set print position so if the first value printed is 129 and the second value printed is 55 then the 9 on the end of 129 will be appended to 55 making 559.

Smaller value pots are probably a good idea, better exchange them for 10k
what kind of pot are you using? wirewound potmeters have a very rough (stepwise) resolution, which could also give problems.
For very smooth control better use cermet or even better plastic film potentiometers

If you are not looking for fast transients from the pot, put a small capacitor, like 1n - 11n, on the wiper / adc pin. It will help alleviate charge transfer when high output impedance is involved.

Also, slowing down the adc is helpful too.

bad connections between pot arduino gnd and 5V ? seen them before

Solved!

Thank's all for the help...

I changed the 3 pot to 10k and rewrite my code...

char buffer[16]="";

void setup ( )
{
  iLCD.begin ( 16, 2 );

}

void loop ()
{
  
 iLCD.home ();
   
  currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 ));
  delay(1);
  currentColorValueGreen = (255 - map(analogRead(greenPotPin), 0, 1023, 0, 255 ));
  delay(1);
  currentColorValueBlue = (255 - map(analogRead(bluePotPin), 0, 1023, 0, 255 ));
  delay(1);
  
  sprintf(buffer, "R:%3dG:%3dB:%3d", currentColorValueRed, currentColorValueGreen, currentColorValueBlue);
  iLCD.print(buffer);
  
}

why
currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 ));

and not

currentColorValueRed = analogRead(redPotPin) /4; // works almost the same (only inverted)

robtillaart:
why
currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 ));

and not

currentColorValueRed = analogRead(redPotPin) /4; // works almost the same (only inverted)

I figured that was the way to reverse the value...I'll try your way to test...

teddycorx:
Smaller value pots are probably a good idea, better exchange them for 10k
what kind of pot are you using? wirewound potmeters have a very rough (stepwise) resolution, which could also give problems.
For very smooth control better use cermet or even better plastic film potentiometers
http://www.resistorguide.com/potentiometer/

High value pots are not a problem if you add a 0.1uF capacitor to ground from the wiper - this will stiffen up the output and kill noise
and allow reliable conversion.