Troubleshooting Odd Servo Behavior

Hi, I am trying to troubleshoot some odd servo behavior we experienced when testing some very simple code on the blimpduino.  We wrote code to simply turn on the right motor, turn it off, turn it on (turning the opposite way), then turn it off, and then repeat that process for the left motor.  Here is the code:

void setup()
{
    //    Initialize the digital pin as an output:
        //      Right motor:
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    digitalWrite(4, LOW);
        digitalWrite(5, LOW);

        //      Left motor:
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(2, LOW);
        digitalWrite(3, LOW);
}

void loop()
{

  //    Turn on right motor (clockwise?), wait for 80 ms, then turn off.  Wait 1 second.
    digitalWrite(5, HIGH);
    delay(80);
    digitalWrite(5, LOW);
    delay(1000);        //    Wait for a second
       
  //    Turn on right motor (anti-clockwise?), wait for 80 ms, then turn off.  Wait 1 second.
        digitalWrite(4, HIGH);
        delay(80);
        digitalWrite(4,LOW);
        delay(1000);

  //    Turn on left motor (clockwise?), wait for 80 ms, then turn off.  Wait 1 second.
    digitalWrite(3, HIGH);
    delay(80);
    digitalWrite(3, LOW);
    delay(1000);        //    Wait for a second
       
  //    Turn on left motor (anti-clockwise?), wait for 80 ms, then turn off.  Wait 1 second.
        digitalWrite(2, HIGH);
        delay(80);
        digitalWrite(2,LOW);
        delay(1000);

}

However, we are getting spikes on the control pin for the servo (white wire) when this code runs.  We confirmed this with an oscilloscope.  Does anybody know why this might be?  Any help would be appreciated, thank you!

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • If this is a normal RC servo then this is not how they are controlled at all.

    RC servos need regular pulses to work, and the length of the pulse and how often you send pulses is critical. Normal RC servos expect to get a pulse 50 times per second (frame time of 20ms) and how long that pulse is will determine were the arm moves to. A 1.5ms long pulse is center, 1.0ms is fully one way and 2.0ms is fully the other way. There is no standard for the direction although you can count on the same model servos always moving the same direction for a given pulse length but not the exact center or end points. The total angle moved can be counted on generally. Another thing of note is you must keep sending the pulses even if you don't need to change the position.

    I am afraid your example above would not work at all. Given the code above and a very good digital servo I would not expect to see any spikes on the control line, on an old analog servo anything is possible, as severe shortcuts were taken with the design to make them cheap and easy to build.
  • Re: spikes - you get a spike when you put a pin HIGH? As in, a higher voltage than +5V? Does the arduino share the power source with the servo?

    Does this happen without the servo (with just the board)?

    Sending it 100% duty cycle might cause it to draw a load of power and do some nasty stuff with your source (and potentially burn out).
  • 3D Robotics
    You've got to output PWM on pins 3 and 5, not just "LOW" or "HIGH"
This reply was deleted.

Activity