Pages: [1]   Go Down
Author Topic: Suggestion on how to change the speed of servo  (Read 323 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,
I want to have different speed serving for my servomotor.  I would like to ask how should I do it?  From the sweep code below that I am currently using, if I wanted to adjust the speed do I adjust either the delay or the increment?  Appreciate any helpful feedback.


Servo myservo;  // create servo object to control a servo
     
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
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26531
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, you could make the parameter of "delay" a variable, or for bonus points, get rid of "delay" altogether.

I'm a bit bored saying this but
Code:
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
clearly it doesn't.
It would be better not to bother with the comment.
« Last Edit: October 12, 2012, 04:33:07 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the sweep code below that I am currently using, if I wanted to adjust the speed do I adjust either the delay or the increment?

Using a larger increment or smaller delay will increase the speed.  Using the next available increment value (2) will double the speed.

Using a larger delay will decrease speed.  You can't use an increment less than 1.

You will have more range of control by changing the delay.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: