2

I am trying to execute the sweep program but all the servo does is go back and forth in one step. When I tried changing the delay, It behaves erratically.

Servo Specs:

Required Pulse: 3-5 Volt Peak to Peak Square Wave
Operating Voltage: 4.8-7.2 Volts
Operating Temperature Range: -10 to +60 Degree C
Operating Speed (4.8V): 0.18sec/60 degrees at no load
Operating Speed (6V): 0.16sec/60 degrees at no load
Operating Speed (7.2V): 0.14sec/60 degrees at no load
Stall Torque (4.8V): 11kg/cm
Stall Torque (6V): 13.5kg/cm
Stall Torque (7.2V): 16kg/cm
360 Modifiable: Yes
Potentiometer Drive: Indirect Drive
Bearing Type: Double Ball Bearing
Gear Type: All Metal Gears
Connector Wire Length: 12"
Dimensions: 1.6" x 0.8"x 1.4" (41 x 20 x 36mm)
Weight: 56gm

Sweep Code:

#include <Servo.h> 

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 

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>=0; 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 tried both powering up internally and externally. Internally it responds but externally, arduino's L LED is high all the time and servo does not respond. May I know what is actually going wrong here.

7
  • 1
    Without code or a schematic it is difficult to help you. Apr 3, 2015 at 12:40
  • @geometrikal I've included the sweep code from the Arduino IDE
    – iBot
    Apr 3, 2015 at 12:42
  • What are you referring to when you say powering internally and externally? Driving a servo requires a variable duty cycle of about [1, 2.5]% or so. The fact that it actually responds to your commands informs us that your signals are changing, albeit not in the correct manner. Make sure you are supplying power and signal to the correct pin on the servo connector - otherwise you may be supplying 100% duty cycle to the signal line and PWM to the power which will not do you any favors. Also, avoid powering the server from the Arduino; the servo current will cause voltage issues.
    – sherrellbc
    Apr 3, 2015 at 13:12
  • Well, its doing what it is programmed to do. You havent included any delay between forward motion and backward motion, so it will go in one direction till 180 deg and then turn back instantly. If you want some delay between forward and backward motion, then add it. (You cant observe 15 ms delay..can you ?)
    – Plutonium smuggler
    Apr 3, 2015 at 14:27
  • Plus consider what will happen in the for loop. In first loop, you have written pos <= 180. When pos is 180, it will still increment it to 181, write it to servo. But servo function only takes upto 180. Similarly in 2nd loop, it will run even when pos is 0 and still decrement it making it -1 (minus 1). I dont know what will happen to servo, but it maybe a cause of error. So better correct that as well.
    – Plutonium smuggler
    Apr 3, 2015 at 14:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.