Lesson 107-8: Controlling the Speed of a 28BYJ-48 Stepper Motor Using a Potentiometer

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

Lesson 107-8: Controlling the Speed of a 28BYJ-48 Stepper Motor Using a Potentiometer

Project 8: Controlling Stepper Motor Using a Potentiometer – 28BYJ-48 Stepper Motor

This article presents the final part of the 8-project series on controlling the 28BYJ-48 stepper motor with Arduino. In Project 8, the stepper motor is controlled via a potentiometer, which allows the user to dynamically change the motor speed and direction by simply rotating the knob. This analog input method is an intuitive and versatile control approach, widely applicable in robotics and motion control systems.

Full wiring diagrams and code for this project are available for download below the article.

📘 Introduction

This setup uses an analog potentiometer connected to an Arduino to read variable voltage values between 0 and 1023. Based on this input, the motor's speed and direction are dynamically adjusted:

  • Rotating the potentiometer clockwise increases speed in one direction.

  • Rotating it counter-clockwise reverses the direction.

⚙️ Wiring

This project connects the potentiometer and stepper motor to the Arduino as follows:

  • Middle pin of potentiometerAnalog pin A0

  • Other two pins5V and GND

  • ULN2003 driver → Pins 8, 10, 9, 11 for the stepper motor

Caption: Project 8 wiring: Potentiometer reads analog input to control speed and direction.


💻 Code Explanation

The code reads analog values and converts them into speed and direction:

  1. Include Library and Define Pins:

#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
  1. Setup Function:

void setup() {
  Serial.begin(9600);
  myStepper.setSpeed(10);
}
  1. Loop Function with Potentiometer Control:

void loop() {
  int sensorValue = analogRead(A0);
  int speed = map(sensorValue, 0, 1023, -15, 15);

  if (speed != 0) {
    myStepper.setSpeed(abs(speed));
    myStepper.step((speed > 0) ? 1 : -1);
  }
  delay(2);
}
  • The map() function converts 0–1023 to -15 to +15 RPM.

  • Speed and direction change in real time as the potentiometer rotates.

  • abs(speed) ensures positive RPM value; direction is handled in step().

🎬 Timestamps from Full Video

Here are the key video timestamps for this project:

  • 1:39:24 – Project 8: Introduction

  • 1:40:58 – Project 8: Wiring

  • 1:44:04 – Project 8: Code

  • 1:53:19 – Project 8: Demonstration



Code Snippets

Comments will be displayed here.