How to control a servo motor.
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
C-Code for sweep function
Below is the C-code made with the WINAVR compiler.
// program name: servo motor controller for sweep function
int pos = 0;
Schematic and board layout potmeter function
C-Code for potmeter function
// program name: servo motor controller with potmeter
#define FOSC 16000000 // clock speed
int main (void)