Society of Robots - Robot Forum

Software => Software => Topic started by: scrubs on March 15, 2008, 01:35:41 PM

Title: servo software
Post by: scrubs on March 15, 2008, 01:35:41 PM
I just got an Arduino and am trying to turn a servo.  The problem is i can't get the servo to turn 90 degrees at once.  With the sample code
from www.arduino.cc (plus some slight modifications) I can still only get my servo to turn about 10 degree steps.  Here is my code:

int servo = 9;
int angle;
int pulseWidth;

void servoPulse(int servo, int angle){
  pulseWidth = (angle * 35);
  digitalWrite(servo,HIGH);
  delayMicroseconds(pulseWidth);
  digitalWrite(servo,LOW);
  delay(20);
}
void setup(){
  pinMode(servo,OUTPUT);
  Serial.begin(9600);
}
void loop(){
  angle = Serial.read();
  angle -= 48;
  Serial.println(angle);
  servoPulse(servo,angle);
  delay(1000);
}

I don't see anything wrong in the code, but im new to robotics so if you see anything pleas say something.

thanks in advance
Title: Re: servo software
Post by: Admin on March 16, 2008, 08:59:40 AM
Quote
I can still only get my servo to turn about 10 degree steps.
What do you mean by 10 degree steps? 0, 10, 20?

if you look at this code:
pulseWidth = (angle * 35);
and lower 35 to something smaller, you can get better resolution

(I think thats what you meant?)