Skip to content

Example 8: Stepper Motor Control ​

Experiment Overview ​

Control a 28BYJ-48 stepper motor via ULN2003 driver board for precise angle and speed control. FastBee has a built-in STEPPER_MOTOR peripheral type (type: 42), supporting half-step drive mode.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
IN1GPIO15ULN2003 Driver Board IN1
IN2GPIO2ULN2003 Driver Board IN2
IN3GPIO0ULN2003 Driver Board IN3
IN4GPIO4ULN2003 Driver Board IN4

ULN2003 module requires external 5V power, 28BYJ-48 stepper motor has 2048 steps per revolution (half-step mode).

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "stepper_01",
      "name": "ULN2003 Stepper Motor",
      "type": 42,
      "enabled": false,
      "pins": [15, 2, 0, 4],
      "params": {
        "stepsPerRevolution": 2048,
        "speed": 8
      }
    }
  ]
}

Parameter Description ​

ParameterDescriptionDefault
stepsPerRevolutionSteps per revolution (28BYJ-48 half-step=2048)2048
speedSpeed (RPM)8

Peripheral Execution Linkage ​

Scenario 1: Forward One Revolution (Platform Trigger) ​

Function: Control motor forward one revolution (2048 steps) via cloud platform command

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Stepper Forward
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Platform TriggerReceive cloud platform commands
    OperatorSelect Match PatternMatch command
    Comparison Value{"cmd":"forward"}Forward command

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in action configuration:

    FieldValueDescription
    Action TypeSelect Call PeripheralCall peripheral method
    Target PeripheralSelect stepper_01Stepper motor peripheral
    Action Params2048Forward 2048 steps (one revolution)
  3. Click Save button

Execution Flow:

Receive forward command
  ↓
Call stepper_01 move method
  ↓
Forward 2048 steps (one revolution)
  ↓
Action complete (blocking execution)

⚠️ Note: stepper_move action blocks the current rule until motor movement completes


Scenario 2: Reverse Half Revolution (Platform Trigger) ​

Function: Control motor reverse half revolution (-1024 steps) via cloud platform command

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click New Rule
  2. Fill in basic configuration:
    • Rule Name: Stepper Reverse
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button
  2. Fill in:
    • Trigger Type: Select Platform Trigger
    • Operator: Select Match Pattern
    • Comparison Value: {"cmd":"reverse"}

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Call Peripheral
    • Target Peripheral: Select stepper_01
    • Action Params: -1024 (negative = reverse, 1024 steps = half revolution)
  3. Click Save button

Steps to Angle Conversion ​

StepsAngleDescription
2048360°One full revolution
1024180°Half revolution
51290°Quarter revolution
25645°Eighth revolution
-2048-360°Reverse one full revolution

Notes ​

  1. Power: Stepper motor needs 5V independent power, ULN2003 cannot be powered from ESP32 3.3V
  2. Heat: Stepper motor still has holding current when stationary, disconnect power when not in use for long periods
  3. Speed Limit: 28BYJ-48 max ~15RPM, exceeding will cause missed steps
  4. Pin Order: IN1-IN4 order must be correct, otherwise motor will vibrate but not rotate
  5. Blocking Execution: stepper_move action blocks the current rule until complete

FastBee | fastbee.cn