本教程是的一部分: 第 107 课 28BYJ-48 步进电机 8 个项目
本视频包含 8 个项目,每个项目都有独立的代码。其他视频的链接位于本文下方。
Lesson 107-6: Controlling a 28BYJ-48 Stepper Motor Using Three Push Buttons, with Angle and Speed STPB-4
Project 6: Variable Angle and Speed Using Push Button STPB-4 – 28BYJ-48 Stepper Motor
This article continues the 8-part stepper motor control series with Project 6, focusing on user-defined motion control using a push button labeled STPB-4. This project allows the user to enter the desired angle and speed through the Serial Monitor, then use a button to execute that motion. It's a powerful setup for testing motion profiles or prototyping motion tasks.
All related source code and wiring diagrams are included below this article.
📘 Introduction
This project introduces custom angle and speed control via serial input. You input the number of degrees to rotate and the desired speed in RPM. Once the data is entered, pressing the STPB-4 button executes the rotation accordingly. This demonstrates how simple input/output interfaces can produce advanced motion control behavior.
âš™ï¸ Wiring
The wiring is consistent with previous projects for the stepper motor and ULN2003 driver. For the button:
One terminal of STPB-4 push button → Arduino pin 2
Other terminal → GND
The system uses the internal pull-up resistor in the Arduino. Serial communication is done over the USB connection.
Caption: Project 6 wiring: Custom angle/speed input via Serial Monitor, execution via STPB-4 button.
💻 Code Explanation
This program combines Serial input parsing with push button control. Here’s how it works:
Initialize Components:
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
const int buttonPin = 2;
int angle = 0;
int speed = 10;Setup Serial and Input:
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Enter angle:");
while (Serial.available() == 0) {}
angle = Serial.parseInt();
Serial.println("Enter speed in RPM:");
while (Serial.available() == 0) {}
speed = Serial.parseInt();
myStepper.setSpeed(speed);
}Loop with Button Trigger:
void loop() {
if (digitalRead(buttonPin) == LOW) {
int steps = (angle * stepsPerRevolution) / 360;
myStepper.step(steps);
delay(1000);
}
}Converts angle to step count based on 2048 steps/revolution.
Motor moves only when button is pressed, using stored values.
🎬 Timestamps from Full Video
Use the following timestamps to find relevant sections in the full tutorial:
1:05:48 – Project 6: Introduction
1:07:43 – Project 6: Wiring
1:11:04 – Project 6: Code
1:17:34 – Project 6: Demonstration
📠Download Section
Full code and wiring resources are provided below this article. This project showcases how to combine hardware interaction and user input for customizable motion applications.
Next up is [Project 7: Multiple Buttons for Angle, Speed, and Direction – STPB-5].
本教程是……的一部分: 第 107 课 28BYJ-48 步进电机 8 个项目
- Lesson 107-1: Start and Stop the 28BYJ-48 Stepper Motor with Direction Set in Code
- Lesson 107-2: Controlling a 28BYJ-48 Stepper Motor via Serial Monitor
- Lesson 107-3: Controlling a 28BYJ-48 Stepper Motor Using Three Push Buttons: CW, CCW, and Stop (STPB-1)
- Lesson 107-4: Controlling a 28BYJ-48 Stepper Motor Using Two Push Buttons, CW, CCW (Keep Pressed), STPB-2
- Lesson 107-5: Send 28BYJ-48 Motor for One Revolution in CW or CCW Direction, STPB-3
- Lesson 107-7: Sending a 28BYJ-48 Stepper Motor to Any Angle with Defined STPB-5 Push Buttons
- Lesson 107-8: Controlling the Speed of a 28BYJ-48 Stepper Motor Using a Potentiometer
This code has not been parsed yet. Please return to the admin panel to parse it.
|||您可能需要的东西
-
全球速卖通Purchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
资源与参考
-
外部Purchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
文件📁
没有可用的文件。