Clearly I'm not using the analog pins correctly...

I'm sure my problem is right in front of my face and I'm just too feeble minded to see it. I am using PWM to control the speed of a linear actuator. Below is my test program. The actuator is sending feedback from a potentiometer.

But the pot isn't giving me any value other than infinite resistance on the wiper (1023). I put the wiper on A0 and the other two on 5V and GND. Even when I used my multimeter and tested wiper to ground I was getting OL on the meter. So there's problem #1- why isn't the resistance changing as the pot moves??

Second, when I lifted the wire from A0, I DID get a value- 246 (fluctuating +- 4 or so). I changed the pin in the program code to A1 just to see what it would read (nothing ever attached to pin A1 except a protoshield) and the first value was 364, and it settled down to 246 after about 10 seconds. What's up with that?

Clearly I am forgetting something fundamental, but what? Thanks!

int motorpin1 = 8;
int motorpin2 = 9;
int pwmspeed = 0;
int updown = 1;



void setup() {

  // initialize serial communications:
  Serial.begin(9600);
pinMode(motorpin1,OUTPUT);
pinMode(motorpin2,OUTPUT);
analogWrite(motorpin1,0);
analogWrite(motorpin2,0);

}

void loop() {

if (pwmspeed > 250) {
    if (updown == 1) updown = 2; else updown = 1;}
if (pwmspeed > 250){pwmspeed =0; }
  
  
  pwmspeed = pwmspeed + 50;
  if (updown == 1) {analogWrite(motorpin1,255); analogWrite(motorpin2,pwmspeed);}
  if (updown == 2) {analogWrite(motorpin1,0); analogWrite(motorpin2,pwmspeed);}
  
  int sensorvalue = analogRead(A1);
  
   // print the acceleration
  Serial.print(pwmspeed);
  // print a tab character:
  Serial.print("\t");
  Serial.print(updown);
   Serial.print("\t");
  Serial.print(sensorvalue);
 
  Serial.println(); 
  
  delay (500);
  
}

But the pot isn't giving me any value other than infinite resistance on the wiper (1023).

The analogue port does not measure resistance but voltage.

Even when I used my multimeter and tested wiper to ground I was getting OL on the meter. So there's problem #1- why isn't the resistance changing as the pot moves??

A broken pot? Or misinterpretation of what pin the wiper is.

So why is there voltage on a pin that isn't connected to anything?

c131frdave:
So why is there voltage on a pin that isn't connected to anything?

Analog input pins that have nothing wired to them are said to be in a 'floating input' condition and if you read them in your sketch you will get random noise values. If you then just wire a ground jumper to the unconnected analog input being read and see then that it calms down to a nice 0 count value.

Great, thanks. Understood.

Now, the wiper is the one that, in a schematic, is in the middle, right? I am connecting the one on the right to +5, the one on the left to ground, and the one in the center to A0.

Edit: Here is a photo of the pot.

I have red on +5, white on GND, and yellow on A0.

Now, the wiper is the one that, in a schematic, is in the middle

Yes, but not all pots have the wiper physically in the middle although most do.
Put the pot somewhere in the middle and measure the resistance from the wiper to each end. It should read half the value of the pot, so for a 1K pot it is 500R from wiper to each end.

If you get no reading then your pot is broken.

Sorry, I was vague. Please see photo above. Thanks!

Eh, I'm so stupid. Red is the wiper. White to yellow is 10k ohms. Red to yellow is 8.5kohms. Red to white is 1.5kohms.

EDIT: It works! I guess getting the wiring correct would be helpful.... Thanks guys!

Muti-turn pots seldom have their wiper as the 'center physical' pin, at least that is my first hand experience. But then i learned years ago to check any pot I was going to use to check it out with an ohm meter so I clearly understood what I had to work with. Even with simple signal turn pots I installed in panels would likely work backwards (as in full volume when turned fully anti-clock wise) if I didn't carefully measure first.

c131frdave:
EDIT: It works! I guess getting the wiring correct would be helpful.... Thanks guys!

As predicted in reply #1