Lesson 107-7: Sending a 28BYJ-48 Stepper Motor to Any Angle with Defined STPB-5 Push Buttons

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

Lesson 107-7: Sending a 28BYJ-48 Stepper Motor to Any Angle with Defined STPB-5 Push Buttons

Project 7: Multiple Buttons for Angle, Speed, and Direction – Using STPB-5 – 28BYJ-48 Stepper Motor

This article is part of the comprehensive 8-project tutorial series on the 28BYJ-48 stepper motor with Arduino. Project 7 demonstrates how to use multiple push buttons to control motor angle, speed, and direction. The setup uses a push button interface (STPB-5) to represent real-world systems where control panels or simple interfaces provide directional input and variable control.

The complete code and wiring schematic are provided below.

πŸ“˜ Introduction

In this project, the user interacts with the system through a multi-button input module (STPB-5), which simulates user choices. Each button corresponds to a specific angle (e.g., 90Β°, 180Β°), a direction (forward/reverse), or a speed. The buttons let you execute complex movements without a computer or serial monitor.


βš™οΈ Wiring

The wiring includes:

  • ULN2003 driver module connected to the stepper motor

  • Multiple push buttons:

    • Button 1: Arduino pin 2 β†’ Direction

    • Button 2: Arduino pin 3 β†’ 90Β°

    • Button 3: Arduino pin 4 β†’ 180Β°

    • Button 4: Arduino pin 5 β†’ Speed

Each button’s other terminal is connected to GND, and all use internal pull-up resistors.

Caption: Project 7 wiring: Four-button STPB-5 setup controlling direction, angle, and speed.

πŸ’» Code Explanation

This program uses four buttons:

  • One toggles direction

  • Two set angle (90Β° or 180Β°)

  • One sets speed

  1. Definitions and Setup:

#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
int dirPin = 2;
int angle90Pin = 3;
int angle180Pin = 4;
int speedPin = 5;
int direction = 1;
int speed = 10;
  1. Setup Function:

void setup() {
  pinMode(dirPin, INPUT_PULLUP);
  pinMode(angle90Pin, INPUT_PULLUP);
  pinMode(angle180Pin, INPUT_PULLUP);
  pinMode(speedPin, INPUT_PULLUP);
  myStepper.setSpeed(speed);
  Serial.begin(9600);
}
  1. Loop Function:

void loop() {
  if (digitalRead(dirPin) == LOW) {
    direction *= -1;
    delay(300);
  }

  if (digitalRead(speedPin) == LOW) {
    speed = (speed == 10) ? 15 : 10;
    myStepper.setSpeed(speed);
    delay(300);
  }

  if (digitalRead(angle90Pin) == LOW) {
    int steps = (2048 * 90) / 360;
    myStepper.step(direction * steps);
    delay(1000);
  }

  if (digitalRead(angle180Pin) == LOW) {
    int steps = (2048 * 180) / 360;
    myStepper.step(direction * steps);
    delay(1000);
  }
}
  • direction toggles between 1 and -1 for forward/reverse

  • Speed toggles between 10 and 15 RPM

  • Buttons execute rotations of 90Β° or 180Β° depending on user input

🎬 Timestamps from Full Video

Refer to the following timestamps for this project:

  • 1:20:18 – Project 7: Introduction

  • 1:21:40 – Project 7: Wiring

  • 1:25:35 – Project 7: Code

  • 1:32:43 – Project 7: Demonstration

πŸ“ Download Section

You can download all necessary files, including source code and wiring diagram, from below. This project introduces a functional multi-button interface, mimicking real-world user control panels.

Next up is [Project 8: Controlling Stepper Motor Using a Potentiometer].

Code Snippets

Comments will be displayed here.