int PWMpin = 5;


int ServoPosition;
int NewServoPosition;

void setup() {
  ServoPosition = 220;
  analogWrite(PWMpin,ServoPosition);
  delay(3000);
}


void loop() {

  // read the potentiometer on A0:
  int sensorReading = analogRead(A0);

  // map the result to 0 - 255
  NewServoPosition = map(sensorReading, 0, 1023, 0, 255);

  //if position has changed upadate PWM
  if (NewServoPosition != ServoPosition){
      ServoPosition = NewServoPosition;
      analogWrite(PWMpin,ServoPosition);
  }

}