
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].
Related Tutorials in This Series:
Lesson 107 28BYJ-48 Stepper 8 Projects
Related Links
- Purchase an authentic Arduino UNO R3 from Amazon USA
- Purchase an authentic Arduino UNO R3: Amazon Canada
- Purchase a 28BYJ-48 stepper motor from Amazon USA
- Purchase a 28BYJ-48 stepper motor from Amazon Canada.
- Purchase a 28BYJ-48 stepper motor from Amazon.
- Purchase 5 pcs 28BYJ-48 stepper motors from AliExpress
- Purchase an Arduino Starter Kit from Amazon USA
- Purchase an Arduino Starter Kit from Amazon Canada
Comments will be displayed here.