Arduino starter kit servo is shaking In the example of the arduino starter kit the point is to use a potenciometer to control a servo.

The code is 

angle = map(potVal, 0, 1023, 0, 179);


The output in the serial

potVal: 1023, angle: 179
potVal: 1015, angle: 177
potVal: 1023, angle: 179
potVal: 1016, angle: 177
potVal: 1023, angle: 179
potVal: 1023, angle: 179


I noticed that the servo is shaking like trying to go passing over the 179, when it is suppose to use an angle max 180º (0-179)

What could be the problem?
If the problem is due to jittery pot readings, you may want to smooth the potval data sequence by code like the following, where rawreading stands for what you just read from the potentiometer's input line.

potval = alpha*potval + (1-alpha)*rawreading;


Set alpha to a number (eg 0.8 or 0.9 or 0.95 etc) between 0 and 1.  alpha represents the fraction of the old value that you retain, and  1-alpha represents the fractional influence of the new raw reading.   alpha closer to 1 causes smoother but slower response.

If you prefer integer arithmetic for faster or smaller code, then represent alpha as a ratio of integers.  For example:

potval = (potval*12 + rawreading)/13;


The technique mentioned above is called exponential smoothing or  exponential moving average.