Notice: Undefined variable: todo_styles in /home/digitalcg/www/wp-content/plugins/bwp-minify/includes/class-bwp-minify.php on line 3120

How to set up a servo with Marlin (Firmware)

For my upcoming experiments I wanted to use a servo with Marlin (firmware). Setting up to 4 servos with Marlin and Ramps board it’s pretty easy. Follow the next steps and you will be ready to go.

But first, I hope you’ll enjoy my demo project, a Fork And Place for candy!

First, set a jumper to supply 5v to the servos. Left side of the reset button connecting the two first pins. And connect the servo to one of the four connectors in the right side.


Next, config Marlin to enable the servos.

Go to Configuration.h and uncomment next line adding the number of servos you want to use:

#define NUM_SERVOS 3 // Servo index starts with 0 for M280 command

Last, edit your GCodes to use M280 PX SX whenever you want to control your servos (P for selecting your servo number and S for the position of it).

And be aware that your G-MOVES aren’t going to wait for your servos positioning, so you might need some delays (G4).

As an small example i built a Fork and Place system based on a servo and a toothpick. Basically the servo moves a piston holding a toothpick. Here some closer pictures:



4 thoughts on “How to set up a servo with Marlin (Firmware)

  1. Joe says:

    Hi is it possible to see your gcode please? Trying to do a similar hack but having issues with delay…

  2. Hi Sorry for the late reply. I changed my computer and I dont have the gcodes I used, but if I would say I needed to add delays because the servo movement was not buffered with the stepper motion. But i might be wrong this was a few years ago.
    Good luck!

  3. vanAnh says:

    Hi, please help me. I also have problem with delay G4 code.
    I use servo to lift up the pen
    When I use G4 P2000 whole system delay include the servo
    after that, XY travel and servo work at the same time
    It not my goal, I need XY stop while pen up or down.


  4. Mark says:

    there is a fork of Marlin by the SFReader that has synchronized movement, i don’t think it’s been tested extensively but here it is:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notice: Undefined variable: todo_styles in /home/digitalcg/www/wp-content/plugins/bwp-minify/includes/class-bwp-minify.php on line 3120