go_away

Author Topic: servo software  (Read 2355 times)

0 Members and 1 Guest are viewing this topic.

Offline scrubsTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
servo software
« 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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,702
  • Helpful? 173
    • Society of Robots
Re: servo software
« Reply #1 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?)

 


Get Your Ad Here