Go Down

Topic: [SOLVED] Continuous rotation servo sometimes stops or goes crazy. (Read 2387 times) previous topic - next topic

defcronyke

May 15, 2014, 09:09 pm Last Edit: May 16, 2014, 12:12 am by defcronyke Reason: 1
Hi,
This is my first try at using any kind of motor, I wanted to eventually make a simple robot so I bought two of these (so the robot could drive around):  "Servo - Generic Full Rotation (Micro Size)" https://www.sparkfun.com/products/10189

It's listed as running on 4.8 - 6 V, and in the comments the sparkfun guy says you can hook it up directly to an arduino, so I did that (hooked it directly to my Arduino Uno):
power to 5v, ground to gnd, and control line to pin 9 on the arduino... I've found the off position of the servo just fine, and it spins fine if only going in one direction. The problem:

If I tell it to spin for a few secs one way, then stop for half a second, then spin for a few secs the other way, then stop, repeat... It does this for a random amount of time fine, but then inevitably either completely stops, or starts spinning full speed in one direction forever.


I can't seem to figure out what I'm doing wrong... I've tried writing the code a few different ways. Here's what I think looks the most correct, but I'm getting that same problem:

Code: [Select]
#include <Servo.h>

Servo serv1;
int serv1_off = 101;
int serv_speed = 20;
int serv_max_speed = 180;
int serv_pulse_time = 20;

void setup()
{
   serv1.attach(9);
}

void loop()
{
   serv_speed = constrain(serv_speed, 0, serv_max_speed - serv1_off);
   for (int i = 0; i < (2000 / serv_pulse_time); i++)
   {
       serv1.write(serv1_off + serv_speed);
       delay(serv_pulse_time);
   }
 
   for (int i = 0; i < (500 / serv_pulse_time); i++)
   {
       serv1.write(serv1_off);
       delay(serv_pulse_time);
   }

   for (int i = 0; i < (2000 / serv_pulse_time); i++)
   {
       serv1.write(serv1_off - serv_speed);
       delay(serv_pulse_time);
   }
 
   for (int i = 0; i < (500 / serv_pulse_time); i++)
   {
       serv1.write(serv1_off);
       delay(serv_pulse_time);
   }
}


The problem happens with both servos, so I doubt the servos are defective. My only guess is my code is wrong, or maybe I really need to run these on a separate 6 V supply... but I'm hoping someone with more experience could help me find where the problem lies.

Robin2

You really need to run the servos from a separate power supply that can provide about 1 amp per servo. Remember to connect the servo power supply ground to the Arduino ground.

When you try to use the Arduino 5v pin and the servos draw too much current the voltage falls and the Arduino behaves strangely - and may get permanently damaged.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

defcronyke

Thanks Robin2,

I can confirm that the problem was exactly what you said, the servo was drawing more current than the Arduino Uno could supply, which was making the arduino go crazy, possibly damaging it too. So it looks like I misinterpreted this statement from Robert C. at SparkFun:

    Glebun | about 3 years ago 1
        what do I need to control this one from arduino?

    RobertC. | about 3 years ago 1
        Nothing, just the arduino and motor:
        http://arduino.cc/en/Tutorial/Knob


It is a true statement, you only need the arduino to control the servo. But you need a separate power supply to power the servo.

I can also confirm that these particular servos work well running on a 5V supply (tested and working: 1 servo on this 5V 2A supply:  "USB Battery Pack - 6600 mAh" https://www.sparkfun.com/products/11360 ). This is a great battery pack because it has two USB outputs, a 1A and a 2A, and it can happily run the arduino on one output while running the servo on the other.

No more craziness! Thanks again Robin2!! Marking topic as solved.

terryking228

Hi,  HERE is: an easy way to separately power the servos.

DISCLAIMER: Mentioned stuff from my own shop...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Go Up