In ths project you can learn how to build a servo controleer motor with the ATMEGA328 board. The position of the servo motor is controlled by the software (sweep back and forth) or by a potentiometer.
The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse roughly every 20 milliseconds. If that pulse is high for 1 millisecond, then the servo angle will be zero, if it is 1.5 milliseconds, then it will be at its centre position and if it is 2 milliseconds it will be at 180 degrees.
Schematic and board layout for sweep function
for more detail:servo motor controller