PC/CP320 Physical Computing

Raspberry Pi Servo Motors and Stepper Motors


Servo motors and stepper motors are common.


  1. To introduce control of servo motors with the Raspberry Pi
  2. To introduce control of stepper motors with the Raspberry Pi


The Raspberry Pi has a PWM output built-in which can help with servo motor control.





Use the optoisolators for the motor signals. This will adjust voltages and protect against EMFs.

  1. Servo motor

    Robot's Servo Drive Motors
    Introduction to Servos

    The Futaba S3003 servos have been modified to run in continuous mode or free running mode. The servo has three wires,

    • red - power 4 to 6 V DC
    • black - ground
    • white or yellow - signal wire

    To drive the motors, a pulse width modulated signal must be sent every 20ms. The width of the pulse will indicate direction and speed:

    • pulse width of 0ms, i.e. no pulse -- the motor will stop
    • pulse width <1.5ms -- the motor will continuously rotate in one direction (clockwise)
    • pulse width = 1.5ms -- the motor is in neutral or dead zone
    • pulse width > 1.5ms -- the motor will continuously rotate in the other direction (counter clockwise)
    • the drive signal is proportional, so the farther it is from the neutral position, the greater the speed
    • NOTE: neutral is approximately at 1.5ms, you must calibrate to get effective speed control
    Suggestions for Investigation and Calibration of Servo Motors
    1. Use the PWM GPIO pin; it will make your life easier. Develop a program to find the neutral or dead zone of one servo motor; do not assume that they are all the same. The neutral zone will be approximately 1.5ms and the motor will stop moving in the neutral zone. Send a pulse every 20ms; note that the period is always 20ms. The program should have a starting pulse width and some mechanism for increasing/decreasing the pulse width. For the pulse width you will need a resolution of at least 0.01ms to find the dead zone; for example, neutral may be at 1.53ms not 1.50ms.

    2. Remember, the closer you are to neutral, the slower the speed of the motor. The farther you are away from neutral, the faster the speed of the motor.
      Determine the duty cycles that give each of the following:
      1. the dead zone
      2. full speed in one direction
      3. full speed in the other direction
      4. about half speed in both directions

    Demonstrate your circuit to the lab supervisor.
  2. Stepper motor

    See the Raspberry Pi Wiki output examples about output to several channels at once.
    Use half-stepping.
    Demonstrate your circuit to the lab supervisor.


To view pdf documents, you can download Adobe Acrobat Reader .
get Acrobat Reader
If you need to update a browser, you might try Firefox which is Get Firefox!
Since this page uses cascading style sheets for its layout, it will look best with a browser which supports the specifications as fully as possible.

If you are looking for an office package, with a word processor, spreadsheet, etc., you might try LibreOffice which is Get LibreOffice!

Go to the main page for the Department of Physics and Computer Science.

Valid XHTML 1.1

Valid CSS!

(Level AA)

Wilfrid Laurier University