本教程是的一部分: 第 107 课 28BYJ-48 步进电机 8 个项目
本视频包含 8 个项目,每个项目都有独立的代码。其他视频的链接位于本文下方。
Lesson 107-4: Controlling a 28BYJ-48 Stepper Motor Using Two Push Buttons, CW, CCW (Keep Pressed), STPB-2
Project 4: Push Button Hold-to-Run Using STPB-2 – 28BYJ-48 Stepper Motor
This article covers the fourth project in the series of 8 tutorials on controlling the 28BYJ-48 stepper motor with Arduino. In this project, the stepper motor is controlled using a push button labeled STPB-2. Unlike the previous project where a single press triggered one full revolution, this setup allows the motor to rotate only while the button is held down.
All source code and wiring diagrams for this project are available below the article.
📘 Introduction
This project demonstrates a continuous motor control mechanism using a momentary push button. When the user holds the button down, the motor continuously steps forward. As soon as the button is released, the motor stops. This method is common in jog controls for industrial machines and testing rigs.
âš™ï¸ Wiring Diagram
The wiring for the stepper motor and ULN2003 remains the same. The button is connected as follows:
One terminal of push button STPB-2 → Arduino pin 2
Other terminal → GND
Internal pull-up resistor is enabled via code
Caption: Project 4 wiring: control motor with continuous motion while STPB-2 is pressed.
💻 Code Explanation
This code setup checks the state of the button continuously and moves the motor one step at a time while the button remains pressed.
Initialize Library and Pins:
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
const int buttonPin = 2;Setup Function:
void setup() {
myStepper.setSpeed(10);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
}Loop Function with Continuous Motion:
void loop() {
if (digitalRead(buttonPin) == LOW) {
myStepper.step(1); // One step at a time
}
}The motor moves one step each loop cycle while the button is held.
Releasing the button immediately stops the motion.
This gives fine-tuned manual control for step-by-step or smooth continuous motion.
🎬 Timestamps from Full Video
Refer to the following sections of the video for this project:
41:07 – Project 4: Introduction
42:29 – Project 4: Wiring
45:31 – Project 4: Code
49:38 – Project 4: Demonstration
📠Download Section
You’ll find complete code and wiring diagrams for this project below. This design is particularly useful for manual machine jogging or continuous feed applications.
Next up is [Project 5: One Revolution Triggered with STPB-3].
本教程是……的一部分: 第 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-5: Send 28BYJ-48 Motor for One Revolution in CW or CCW Direction, STPB-3
- Lesson 107-6: Controlling a 28BYJ-48 Stepper Motor Using Three Push Buttons, with Angle and Speed STPB-4
- 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
文件📁
没有可用的文件。