Servo on pot - hehe

For some reason when I hook my servo up to a pot, it becomes lazy and will only move in one direction. Why won't it move in both directions? Here is the sketch I'm using.

#include <Servo.h>

Servo panservo;

int potpin = 1;
int val;

void setup()
{
panservo.attach(10);
}

void loop()
{
val = analogRead(potpin);
val = map(val, 0, 100023, 0, 179);
panservo.write(val);

}

val = map(val, 0, 100023, 0, 179);

Try this

val = map(val, 0, 1023, 0, 179);

But I'm using 100k pot.

val = map(val, 0, 100023, 0, 179);

That 100023 should be a 1023 to work as expected.

But I'm using 100k pot.

That has nothing to do with what you are doing.
The pot is varying the voltage on the pin between 0 and 5V (If you have connected it like i think you have)
The 0 to 5V is translated by the ADC to a value between 0 and 1023.

But I'm using 100k pot.

Doesn't matter. The output of the pot wiper will still be 0-5v (assuming the pot is properly connected between +5v and ground on the arduino).

Erni:

But I'm using 100k pot.

That has nothing to do with what you are doing.
The pot is varying the voltage on the pin between 0 and 5V (If you have connected it like i think you have)
The 0 to 5V is translated by the ADC to a value between 0 and 1023.

Doesn't matter. The output of the pot wiper will still be 0-5v (assuming the pot is properly connected between +5v and ground on the arduino).

Well actually it can. The analog input pin is designed to work best when driven by 10k ohms of source resistance or lower, a 100k ohm pot can make getting smooth valid conversions difficult. I would suggest getting a 5k or 10k ohm pot for best results.

Lefty

I picked up a 10k pot on my way to work, so when I get home I'll give it a shot. By the time I left, I had the 100k moving in both directions, however it was a small rang of motion and the pot only worked in a small range as well. Thanks for the help

Well, I changed everything around... I put on the 10k pot and made the proper changes to the sketch (see below). Now, the servo is only moving a small distance maybe 10 degrees in total each way when I move the pot. On top of that I have to stay in a very small section of the pot for this to work. It will not work going from 0 - 10k it only works in the lower section of the pot I would say 0 ohms to 1 ohm. I noticed that I'm getting very low voltage on it as well, when it's moving I'm only getting approx. 2.5v, so I'm sure that has something to with it. I think I will try to hook it up to my external supply.

UPDATE
It was not working due to the voltage drop when i have it plugged in USB with all the other things on there. It seems to be working well, It's not moving to the max degrees but it's good enough for what I'm using it for.

Thanks for all the help guys!!!!!!!!!!