Arduino Stepper Motor with Rotary Encoder
Level 25 · Level 25 — Exactly There · 25 minutes
Steps, not speed. A stepper goes exactly where it is told, and a knob says where that is.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
One knob click moves the shaft exactly 45 degrees, the way you turned it. Wire it up: - Driver board: VCC to 5V, GND to GND, IN1-IN4 to D8-D11 - Encoder: VCC to 5V, GND to GND, CLK to D2, DT to D3 Work out how many half-steps 45 degrees is. Print your target angle as Target: 45.
Components you’ll use
- Arduino Uno
- Stepper Motor (28BYJ-48 + ULN2003)
- Rotary Encoder (KY-040)
What you'll build
A knob that turns the shaft exactly 45 degrees per click, either way.
How it works
- A stepper is never told a speed. Tell it to take one half-step, its smallest move, and it takes exactly one.
- Count your steps and you know where the shaft is. Nothing measures it: open-loop positioning, how a 3D printer knows where it is.
- A potentiometer has a position you read. The KY-040 has none: two switches, CLK and DT, a quarter-click apart.
- When CLK drops low, read DT. High is clockwise, low is back. Swap them and you print Target: -45.
- Two counters, then: one the knob moves, one the coils move. Close the gap one step at a time.
The key idea
64 half-steps turn the motor's own hidden rotor once. Between that rotor and the white spindle sits a gearbox of about 64 to 1.
64 × 64 = 4096 half-steps per shaft turn
45 degrees = 4096 / 8 = 512 half-steps
⚠ Watch out
- Forget the driver board's VCC: the sketch runs perfectly, the shaft never moves.
- The coil table is an order, not a set. Scramble it and the motor buzzes and stays put; the grader counts the jumps.
- Use 2048, 64 or 32 instead of 4096 and the sketch runs beautifully, stopping in the wrong place. Nothing is watching.
The interactive editor includes the wiring guide, code editor and simulation controls.