Schematic and board layout for sweep function

servo motor controller sch

  servo motor controller brd

C-Code for sweep function

Below is the C-code made with the WINAVR compiler.

// program name: servo motor controller for sweep function
// date: 27-jun-2017
// author: www.avrprojects.net
// target device : ATMEGA328

#include <avr/io.h>
#include <util/delay.h>
#define F_CPU = 16000000;


int main (void)

{
DDRB = 0xFF; // set portb for output
PORTB = 0;

int pos = 0;
while(1)
{
for (pos = 750; pos <= 2250; pos += 10)
{
PORTB = 0x00000001;
_delay_us (pos);
PORTB = 0x00000000;
_delay_us (20000 - pos);
}
for (pos = 2250; pos >= 750; pos -= 10)
{
PORTB = 0x00000001;
_delay_us (pos);
PORTB = 0x00000000;
_delay_us (20000 - pos);
}
}
}