Configure a 28BYJ-48 Stepper Motor

The 28byj48 model of the motor component supports small unipolar stepper motors controlled by stepper motor drivers like ULN2003. The 28byj48 is often used for low-current and low-precision applications and supports full, half, and quarter stepping with 4096 steps in a rotation in full-step mode.

To configure a 28byj48 motor as a component of your machine, first configure the board to which the motor driver is wired. Then, add the motor:

Navigate to the CONFIGURE tab of your machine’s page in the Viam app. Click the + icon next to your machine part in the left-hand menu and select Component. Select the motor type, then select the 28byj48 model. Enter a name or use the suggested name for your motor and click Create.

A 28byj48 motor config.

Edit and fill in the attributes as applicable.

{
  "components": [
    {
      "name": "<your-board-name>",
      "model": "<your-board-model>",
      "type": "board",
      "namespace": "rdk",
      "attributes": {},
      "depends_on": [],
    },
    {
      "name": "<your-motor-name>",
      "model": "28byj48",
      "type": "motor",
      "namespace": "rdk",
      "attributes": {
        "board": "<your-board-name>",
        "pins": {
          "in1": "<pin-number>",
          "in2": "<pin-number>",
          "in3": "<pin-number>",
          "in4": "<pin-number>"
        },
        "ticks_per_rotation": <int>
      },
      "depends_on": []
    }
  ]
}

Example configuration for a 28byj48 stepper motor:

{
  "components": [
    {
      "name": "example-board",
      "model": "pi",
      "type": "board",
      "namespace": "rdk"
    },
    {
      "name": "example-motor",
      "model": "28byj48",
      "type": "motor",
      "namespace": "rdk",
      "attributes": {
        "board": "example-board",
        "pins": {
          "in1": "11",
          "in2": "12",
          "in3": "13",
          "in4": "15"
        },
        "ticks_per_rotation": 4096
      }
    }
  ]
}

The following attributes are available for 28byj48 motors:

NameTypeInclusionDescription
boardstringRequiredname of the board the motor driver is wired to.
pinsobjectRequiredA JSON object containing the pin numbers the in1, in2, in3, and in4 pins of the motor driver are wired to on the board.
ticks_per_rotationintRequiredNumber of full steps in a rotation. The motor takes 5.625*(1/64)° per step. One full rotation (360°) is 4096 steps.

Refer to your motor and motor driver data sheets for specifics.

An example wiring diagram for a four wire 28BYJ-48 stepper motor driven by a ULN2003A driver chip breakout board. The driver is connected to a Raspberry Pi with four wires labeled IN1, IN2, IN3, and IN4. These are connected to Pi pins 11, 12, 13 and 15, respectively. A separate 12V power supply is attached to the motor driver to power the motor.

Test the motor

Once your motor is configured and connected, go to the CONTROL tab and click on the motor’s dropdown panel. Use the buttons to try turning your motor forwards or backwards at different power levels and check whether it moves as expected.

Motor control panel.

If the motor does not appear on the CONTROL tab, or if you notice unexpected behavior, check your machine’s LOGS tab for errors, and review the configuration.

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.