Stepper motor that follows a knob
Build it step by step
0 of 4 donePlug in the motor
The connector only fits one way into the ULN2003 board.
Wire the driver
IN1 to IN4 to D8 to D11. Motor power from the AA pack, ground shared with the Uno.
Wire the pot
Outer pins to 5V and GND, middle to A0.
Upload and turn
Put a paper arrow on the shaft, turn the knob slowly and watch the arrow follow.
How do you build a stepper motor that follows a knob?
A 28BYJ-48 stepper on a ULN2003 board turns to match a potentiometer, with smooth acceleration from the AccelStepper library. You need Arduino Uno R3, 28BYJ-48 Stepper Motor, ULN2003 driver board, Potentiometer 10 kΩ, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 400 points (half size) and Jumper wires male to female (40 pcs). It takes 4 steps and about 50 minutes.
- Level
- Beginner
- Time
- About 50 min
- Parts
- 8
Wiring
| From | To | Why |
|---|---|---|
| Stepper plug | ULN2003 board socket | Five-wire motor connector |
| ULN2003 IN1 / IN2 / IN3 / IN4 | Uno D8 / D9 / D10 / D11 | Coil sequence |
| ULN2003 + / − | 4 × AA + / − | Motor power (about 240 mA) |
| 4 × AA − | Uno GND | Shared ground |
| Pot outer pins / wiper | Uno 5V and GND / A0 | Target position |
Code
Arduino IDE, board "Arduino Uno". Install "AccelStepper" by Mike McCauley. Note the pin order 8, 10, 9, 11 in the code.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <AccelStepper.h>
// HALF4WIRE with the pin order IN1, IN3, IN2, IN4 suits the 28BYJ-48
AccelStepper motor(AccelStepper::HALF4WIRE, 8, 10, 9, 11);
const long STEPS_PER_TURN = 4096; // half steps, including the 64:1 gearbox
void setup() {
motor.setMaxSpeed(800);
motor.setAcceleration(400);
}
void loop() {
int raw = analogRead(A0);
long target = map(raw, 0, 1023, 0, STEPS_PER_TURN); // knob range = one full turn
if (abs(target - motor.targetPosition()) > 8) motor.moveTo(target);
motor.run();
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Knob fully left | Shaft at the start position |
| Knob fully right | Shaft one full turn (360°) from the start |
| Knob to the middle | Shaft about half a turn (180°) |
| ULN2003 LEDs | Flicker in sequence while it moves |
If it does not work
Motor buzzes but does not turn
Wrong pin order. Use 8, 10, 9, 11 as in the code.
Shaft jitters at rest
Raise the dead band (8) to 16 so noise on A0 is ignored.
Very weak
The 28BYJ-48 is a small geared motor. Lower setMaxSpeed to 500 for more torque.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the stepper motor that follows a knob?
Arduino Uno R3, 28BYJ-48 Stepper Motor, ULN2003 driver board, Potentiometer 10 kΩ, Battery holder 4 × AA with switch, AA alkaline battery × 4, Breadboard 400 points (half size) and Jumper wires male to female (40 pcs).
How long does the stepper motor that follows a knob take to build?
About 50 minutes for a beginner maker, in 4 steps.
How do I know the stepper motor that follows a knob works?
Knob fully left: Shaft at the start position. Knob fully right: Shaft one full turn (360°) from the start. Knob to the middle: Shaft about half a turn (180°).
Motor buzzes but does not turn: what should I check?
Wrong pin order. Use 8, 10, 9, 11 as in the code.
Shaft jitters at rest: what should I check?
Raise the dead band (8) to 16 so noise on A0 is ignored.
Very weak: what should I check?
The 28BYJ-48 is a small geared motor. Lower setMaxSpeed to 500 for more torque.
