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].
الأشياء التي قد تحتاجها
-
علي إكسبريسPurchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
الموارد والمراجع
-
خارجيPurchase 5 pcs 28BYJ-48 stepper motors from AliExpresss.click.aliexpress.com
-
خارجي
-
خارجي
-
خارجي
-
خارجي
-
خارجي
ملفات📁
لا توجد ملفات متاحة.