# programming VS-2 servo motor

#### jayk

Joined Dec 18, 2011
3
I have done the following program but servo motor is rotating fully. I cant control the angle.

Rich (BB code):
#include<avr/io.h>
#include<compat/deprecated.h>
#include<util/delay.h>

main()
{
sbi(DDRD,5);

while(1)
{
int i;

for(i=10000; i > 0; i--)
{
sbi(PORTD,5);
_delay_ms(0.6);
cbi(PORTD,5);
_delay_ms(19.4);
}

for(i=10000; i > 0; i--)
{
sbi(PORTD,5);
_delay_ms(1.5);
cbi(PORTD,5);
_delay_ms(18.5);
}

for(i=10000; i > 0; i--)
{
sbi(PORTD,5);
_delay_ms(2.4);
cbi(PORTD,5);
_delay_ms(17.6);
}

}
}

Last edited by a moderator:

#### Markd77

Joined Sep 7, 2009
2,806
Are you waiting long enough for it to move? 10000 X 20ms = 200 seconds

#### jayk

Joined Dec 18, 2011
3
then how long should i wait.can you give me suggestion

#### Markd77

Joined Sep 7, 2009
2,806
According to the code it should change position every 200 seconds which is 3 minutes and 20 seconds.

#### thatoneguy

Joined Feb 19, 2009
6,359
You are only setting and clearing port D.5, so it will only go in one direction, if it moves at all.

Need a schematic of how everything is hooked together to really give advice. Usually at least 3 pins are used, one for enable, and one for fwd/reverse or phase if using a stepper.