noob with his first sketch.

im trying to do a simple sketch using one of the example sketches to power a servo i have. just to mess around and get some experience with the duemilanove. this is my code. i know i missing something.

// Sweep
// by BARRAGAN http://barraganstudio.com

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = (0); // variable to store the servo position

void setup()
{
myservo.attach(0); // attaches the servo on pin 0 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

it also gives these error codes in the console.

avrdude: stk500_getsync(): not in sync: resp=0x30
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

help please?

Have you tried the search function.

Just type in "stk500 sync error" and it should bring up a lot of posts from people having the same problems.

Hope that helps

opps. forgot about the search bar. -_-*

but help is help. thanks. :slight_smile:

more would be appreciated.

You are trying to attach pin 0 to the servo - pin 0 is used by the serial port. If you are using the arduino servo library that is distributed with the latest release, try attaching it to pin 9.

this page may help: Servo - Arduino Reference

ok i fixed it. i had the wrong board selected. it loads.

but. how do i tell it to run? facepalm

ok. pin 9. it works!!!!! :smiley: my first sketch!!!! yay!!!

ok. when i try and modify the sweep value from 180 to say 90 or 45, it just keeps spinning. no stops. i changed both values for the 90-0 and the 0-90 but it doesnt change.

Good to hear you have it going. post your latest code of you would like someone to have a look.

new code.

// Sweep
// by BARRAGAN http://barraganstudio.com

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = (0); // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

I think you posted the old code. I thought you wanted help with code that used different sweep values?

i couldnt remember if i had changed it or not so i just sopy+pasted the one i was working on right then.

im still trying to figure out why, when i change the (180) to (45) or (90) , it continues to go in a circle with no stops.

continues to go in a circle with no stops.

can you clarify what you mean.

Has the servo been modified for continuous rotation?

lol, be sure not to use pins 1 or 0!

yeah i had forgotten it was a continuous rotation servo facepalm but i switched it out and now its working like its supposed to :smiley: