Fast Potentiometer movement and Servo control

Hey Guys,

iam steering and Servo with a Potentiometer. But when i move the Poti to fast the Servo stucks or will not reach the final Position. Is there a Way to fix this ?

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(8);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

Moderator edit: [sup] tag corrected

myservo.attach(8); // attaches the servo on pin 9 to the servo object

No, it doesn't

What ?

Make the delay bigger.

hegi:
What ?

He's on second base.

Grumpy_Mike:
Make the delay bigger.

i tried Delays from 20-500. it makes is even worse

UNCOMPILED, UNTESTED

#include <Servo.h>
Servo myservo;
const int FACTOR = 4;
const byte potpin = A0; 
int pos = 90;

void setup() 
{
  myservo.write (pos);
  myservo.attach(8);
}

void loop() {
  int val = map(analogRead(potpin), 0, 1024, 0, 180);
  pos = ((pos * (FACTOR - 1)) / FACTOR) + (val / FACTOR)
  myservo.write(pos);
  delay(15);
}

Is there a Way to fix this ?
[/quote]

hegi:
when i move the Poti to fast the Servo stucks or will not reach the final Position. Is there a Way to fix this ?

Avoid poor power supply for the servo (i.e. do not use Arduino board 5V pin for servo power supply)!
Use only good and adequate power supply for the servo!

And remove the delay() from your code!

AWOL:
UNCOMPILED, UNTESTED

#include <Servo.h>

Servo myservo;
const int FACTOR = 4;
const byte potpin = A0;
int pos = 90;

void setup()
{
  myservo.write (pos);
  myservo.attach(8);
}

void loop() {
  int val = map(analogRead(potpin), 0, 1024, 0, 180);
  pos = ((pos * (FACTOR - 1)) / FACTOR) + (val / FACTOR)
  myservo.write(pos);
  delay(15);
}

Thank you that works good.