Lesson 107-6: Controlling a 28BYJ-48 Stepper Motor Using Three Push Buttons, with Angle and Speed STPB-4

Video thumbnail for Using 28BYJ-48 Stepper Motor Push button Speed with 8 projects: Ultimate Video Tutorial Lesson 107

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:

  1. 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;
  1. 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);
}
  1. 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].



Code Snippets

Comments will be displayed here.