SG90 180 degree servos only turning 90 degrees

Posted on
  • Hi folks

    Just had a set of SG90 servos delivered and having trouble with the servo module.

    The example here: http://www.espruino.com/Servo+Motors#lin­e=13,25,26 shows it moving from 0 to 1, which is actually only 90 degrees, not 180 as these servos support.

    If you use:

    analogWrite(pin, 0.04, {freq:50});
    

    It goes to -90 ... and

    analogWrite(pin, 0.15, {freq:50});
    

    It goes to +90, demonstrating the full 180 degrees of motion... but the servo module doesn't seem to support it. They require either 1 (-90), 1.5 (0 or middle) or 2ms (+90) pulses at 50Hz

    Any help would be appreciated.

  • The servo module outputs between 1ms and 2ms pulses - which would (at least from Wikipedia) seem to be what you expect for -90 to +90 degree pulses: https://en.wikipedia.org/wiki/Servo_cont­rol

    It tries to clip them to avoid damage to the servo motor. To get -90 you're having to output 0.04*1000/50 = 0.8ms, and 3ms(!!!!) for +90. At 3ms I think you probably are running your servo motor against the endstop, which could blow it up if you leave it there for any time.

    This is a really common thing though and I'm tempted to say that Wikipedia isn't entirely right about the correct range of pulse lengths, so I just changed the module.

    If you upload your code now, but change the initialisation to require("servo").connect(C7,{range:2}); then it'll output from 0.5ms to 2.5ms - and you could tweak the range as you see fit to match your servo.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

SG90 180 degree servos only turning 90 degrees

Posted by Avatar for user74538 @user74538

Actions