
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 potentiometer → Analog pin A0
Other two pins → 5V 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:
Include Library and Define Pins:
#include <Stepper.h>
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
Setup Function:
void setup() {
Serial.begin(9600);
myStepper.setSpeed(10);
}
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 instep()
.
🎬 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
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
Comments will be displayed here.