Example 8: Stepper Motor Control
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| IN1 | GPIO15 | ULN2003 Driver Board IN1 |
| IN2 | GPIO2 | ULN2003 Driver Board IN2 |
| IN3 | GPIO0 | ULN2003 Driver Board IN3 |
| IN4 | GPIO4 | ULN2003 Driver Board IN4 |
ULN2003 module requires external 5V power, 28BYJ-48 stepper motor has 2048 steps per revolution (half-step mode).
JSON Configuration Example
{
"peripherals": [
{
"id": "stepper_01",
"name": "ULN2003 Stepper Motor",
"type": 42,
"enabled": false,
"pins": [15, 2, 0, 4],
"params": {
"stepsPerRevolution": 2048,
"speed": 8
}
}
]
}Parameter Description
| Parameter | Description | Default |
|---|---|---|
| stepsPerRevolution | Steps per revolution (28BYJ-48 half-step=2048) | 2048 |
| speed | Speed (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
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Stepper Forward - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Platform Trigger Receive cloud platform commands Operator Select Match Pattern Match command Comparison Value {"cmd":"forward"}Forward command
Step 3: Configure Action
Click Add Action button
Fill in action configuration:
Field Value Description Action Type Select Call Peripheral Call peripheral method Target Peripheral Select stepper_01Stepper motor peripheral Action Params 2048Forward 2048 steps (one revolution) 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
- Click New Rule
- Fill in basic configuration:
- Rule Name:
Stepper Reverse - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 2: Configure Trigger
- Click Add Trigger button
- Fill in:
- Trigger Type: Select Platform Trigger
- Operator: Select Match Pattern
- Comparison Value:
{"cmd":"reverse"}
Step 3: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Call Peripheral
- Target Peripheral: Select
stepper_01 - Action Params:
-1024(negative = reverse, 1024 steps = half revolution)
Click Save button
Steps to Angle Conversion
| Steps | Angle | Description |
|---|---|---|
| 2048 | 360° | One full revolution |
| 1024 | 180° | Half revolution |
| 512 | 90° | Quarter revolution |
| 256 | 45° | Eighth revolution |
| -2048 | -360° | Reverse one full revolution |
Notes
- Power: Stepper motor needs 5V independent power, ULN2003 cannot be powered from ESP32 3.3V
- Heat: Stepper motor still has holding current when stationary, disconnect power when not in use for long periods
- Speed Limit: 28BYJ-48 max ~15RPM, exceeding will cause missed steps
- Pin Order: IN1-IN4 order must be correct, otherwise motor will vibrate but not rotate
- Blocking Execution: stepper_move action blocks the current rule until complete
