• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

Arduino Stepper with Potentiometer Speed Control

You are here: Home / Electronics and Hardware / Arduino Stepper with Potentiometer Speed Control
Author: Chris Garrett

For my 3D printed turntable I obviously need some way to turn the turntable, and preferably for video and scanning, some method to control speed.

Fortunately, I have a whole box full of those cheap and ubiquitous stepper motors, the 28YBJ-48 plus the ULN2003 driver board.

28YBJ-48 and the ULN2003. Stepper motor under Arduino control
28YBJ-48 and the ULN2003. Stepper motor under Arduino control

These guys are 5v DC, the boards accept 5-12v, but each 28YBJ-48 motor can draw up to 320mA, so while initially, you can use 5v, we will use external power attached to the 5-12v in, and ground attached to our battery pack and our Arduino.

To control the motor the stepper attaches to the driver board with 4 data lines and power. Our Arduino connects four pins, (3, 5, 4 and 6) to IN1-IN4 on the ULN2003 controller board.

Our potentiometer supplies an analog signal which we attach to A0, 3v and ground.

View this post on Instagram

A post shared by Maker Hacks DIY Projects ?? (@maker_hacks)

Arduino C Code

Also find the code at this Gist


//Arduino stepper library
#include <Stepper.h>

// different steppers have different
// amount of steps to do a full
// turn of the wheel.
#define STEPS 32

// connections need to be done carefully
// In1-In4 are added in the sequence 1-3-2-4
Stepper stepper(STEPS, 3, 5, 4, 6);

// the number of steps to take
int numSteps;

// Only serial to setup here
void setup() {

  Serial.begin(115200); // start serial
  
}


// loop runs constantly
void loop() {

  // full revolution
  numSteps = (STEPS * 64) /100;

  // max power is 1024
  stepper.setSpeed( getMotorSpeed() );
  
  // take the steps
  // you can reverse direction with -numSteps
  stepper.step(-numSteps);
 

}

int getMotorSpeed() {

    // read the sensor value:
  int sensorReading = analogRead(A0);
  Serial.println(sensorReading);
  
  // map it to a range from 0 to 1024:
  int motorSpeed = map(sensorReading, 0, 769, 0, 1024);
  
  // set the motor speed:
  if (motorSpeed > 0) {
    return motorSpeed;
  }

}
  


Category: Electronics and HardwareTag: arduino, Hacks, making, robots

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Chris on Ko-Fi to get exclusive content and rewards!

Previous Post:raspberry pi security cameraRaspberry Pi Security Camera
Next Post:5 Best Tools for Makers of 2018

Sidebar

  • Facebook
  • Instagram
  • YouTube

Featured Posts

  • CyberBrick Review + Getting Started
  • xTool M2 Review
  • xTool F2 Ultra Review
  • xTool F2 Review
  • xTool S1 Review
  • Anycubic Kobra S1 Combo Review
  • Makera Z1 Pro Review
  • CNC Buyer's Guide
  • eufyMake E1 UV Printer Review
  • eufyMake Purifier P1
  • Z80 on a Breadboard
  • OpenSCAD MakerWorld Customizer

30 Days to Arduino

Arduino Tutorials
  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi Reviews technology tips xtool xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy