Pages: [1]   Go Down
Author Topic: Analogin Pot value inaccuracy  (Read 1223 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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 ));
}
Logged

Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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??
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Norfolk UK
Offline Offline
Edison Member
*
Karma: 65
Posts: 2442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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/
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Solved!

Thank's all for the help...

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

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);
  
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

and not

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

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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...
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11650
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: