Forum >Servos for Arduino
ArduinoGeneral

Servos for Arduino

userHead Leff 2016-04-06 00:09:25 2160 Views0 Replies

This post is to solve how to accelerate servo properly. I got a question from one of our customers like this:

 

I just bought a DF Metal Geared 15Kg Standard Servo 270° (DSS-M15S) and it works well with the sweep arduino test;

https://www.arduino.cc/en/Tutorial/Sweep

But when I modify the test to have steps of 10 degree (instead of 1 degree as in the default test) I only have two shorts movements and that's all. 

Any suggestion to make this exemple working for 10 degree steps? 



1. Please change the code delay(15); once you change the pace. I tested that once changed pace from 1 to 10, then 50 milliseconds should be waited, this can be known by the sample comments "waits 15ms for the servo to reach the position ", and this is what I tested on DF Metal Geared 15Kg Standard Servo 270° (DSS-M15S).

 

Code: Select all#include 

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int tar = 180;
int spe = 10;
int de = 50;

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

void loop() {
  for (pos = 0; pos <= tar; pos += spe)  {
    myservo.write(pos);
    delay(de);
  }
  for (pos = tar; pos >= 0; pos -= spe)  {
    myservo.write(pos);
    delay(de);
  }
}

 




2. Please supply a powerful & suitable adapter for servo through Arduino card.

Related topic on power Arduino.


3. It is tested that the variable spe in for(... , pos -= spe) doesn't represent real angle, you can only set it between 0-180. That is when you set it to 180, the servo will rotate to its maxmum angle (270° is what I used here).