Projects / Stepper motor first steps

Stepper motor first steps

Beginner30 minGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNO

    Wire the driver

    Connect IN1 to IN4 to D8 to D11 and the 5 V and ground.

  2. UNO

    Plug in the motor

    Use the white five-pin plug in the board socket.

  3. UNO

    Upload

    The motor should make one full turn at start.

  4. UNO

    Count the turn

    Mark the shaft and check it comes back to the start.

  5. UNO

    Move by 90 degrees

    Press the two buttons to move a quarter turn each way.

  6. UNO

    Change speed

    Reduce stepDelayMs until the motor starts to skip, then raise it a little.

  7. UNO

    Try full-step mode

    Set halfStep to false and compare the sound and smoothness.

In short

How do you build a stepper motor first steps?

Turn a 28BYJ-48 stepper a full turn, then exact angles, and see how step sequences work. You need Arduino Uno R3, 28BYJ-48 Stepper Motor, ULN2003 driver board, Tactile push button 6 mm × 2, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and 5 V 2 A USB adapter. It takes 7 steps and about 30 minutes.

Level
Beginner
Time
About 30 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ULN2003 board IN1Uno D8Coil 1
ULN2003 board IN2Uno D9Coil 2
ULN2003 board IN3Uno D10Coil 3
ULN2003 board IN4Uno D11Coil 4
Stepper motor connectorULN2003 board socketFive-wire plug
5 V adapter +ULN2003 + terminalMotor power
5 V adapter -ULN2003 - terminal and Uno GNDCommon ground
Button forwardUno D2 and GNDMove 90 degrees one way
Button backUno D3 and GNDMove 90 degrees the other way

Code

The 28BYJ-48 has an internal gearbox, so about 2048 full steps (or 4096 half steps) turn the output shaft once. The ULN2003 board switches the four coils from the Uno pins; the motor needs its own 5 V supply and a shared ground, not the Uno pin. In half-step mode the sequence alternates between one coil and two coils, which gives smoother motion and twice the resolution. If the shaft only vibrates, the coil order is wrong: check the plug and the pin order. Releasing the coils after a move stops the motor and driver getting warm, but it also removes the holding torque. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).

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).

// 28BYJ-48 half-step and full-step sequences, driven by hand without a library.
const byte PINS[4] = {8, 9, 10, 11};
const byte HALF[8][4] = {{1,0,0,0},{1,1,0,0},{0,1,0,0},{0,1,1,0},{0,0,1,0},{0,0,1,1},{0,0,0,1},{1,0,0,1}};
const byte FULL[4][4] = {{1,1,0,0},{0,1,1,0},{0,0,1,1},{1,0,0,1}};

bool halfStep = true;               // true: 4096 steps per turn, false: 2048
int phase = 0;
int stepDelayMs = 3;                // lower is faster; below about 2 it may skip

void apply(const byte *p) { for (byte i = 0; i < 4; i++) digitalWrite(PINS[i], p[i]); }

void oneStep(int dir) {
  if (halfStep) { phase = (phase + dir + 8) % 8; apply(HALF[phase]); }
  else          { phase = (phase + dir + 4) % 4; apply(FULL[phase]); }
  delay(stepDelayMs);
}

void moveSteps(long n) {
  int dir = n > 0 ? 1 : -1;
  for (long i = 0; i < labs(n); i++) oneStep(dir);
  for (byte i = 0; i < 4; i++) digitalWrite(PINS[i], LOW);   // release the coils to avoid heat
}

void setup() {
  for (byte i = 0; i < 4; i++) pinMode(PINS[i], OUTPUT);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  Serial.begin(9600);
  moveSteps(halfStep ? 4096 : 2048);   // one full turn at the output shaft
}

void loop() {
  long quarter = halfStep ? 1024 : 512;   // 90 degrees
  if (digitalRead(2) == LOW) { moveSteps(quarter); delay(200); }
  if (digitalRead(3) == LOW) { moveSteps(-quarter); delay(200); }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Start-upOne full turn of the output shaft
Button forwardQuarter turn one way
Button backQuarter turn the other way
Delay too smallMotor skips or stalls

If it does not work

Only vibrates

Check the pin order in the PINS array and the plug.

Does not move

Check the separate 5 V supply and the common ground.

Gets hot

Release the coils after moving; it already does in this sketch.

Skips steps

Increase stepDelayMs and check the supply.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the stepper motor first steps?

Arduino Uno R3, 28BYJ-48 Stepper Motor, ULN2003 driver board, Tactile push button 6 mm × 2, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and 5 V 2 A USB adapter.

How long does the stepper motor first steps take to build?

About 30 minutes for a beginner maker, in 7 steps.

How do I know the stepper motor first steps works?

Start-up: One full turn of the output shaft. Button forward: Quarter turn one way. Button back: Quarter turn the other way.

Only vibrates: what should I check?

Check the pin order in the PINS array and the plug.

Does not move: what should I check?

Check the separate 5 V supply and the common ground.

Gets hot: what should I check?

Release the coils after moving; it already does in this sketch.

Skips steps: what should I check?

Increase stepDelayMs and check the supply.