Build it step by step
0 of 7 doneWire the driver
Connect IN1 to IN4 to D8 to D11 and the 5 V and ground.
Plug in the motor
Use the white five-pin plug in the board socket.
Upload
The motor should make one full turn at start.
Count the turn
Mark the shaft and check it comes back to the start.
Move by 90 degrees
Press the two buttons to move a quarter turn each way.
Change speed
Reduce stepDelayMs until the motor starts to skip, then raise it a little.
Try full-step mode
Set halfStep to false and compare the sound and smoothness.
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
Wiring
| From | To | Why |
|---|---|---|
| ULN2003 board IN1 | Uno D8 | Coil 1 |
| ULN2003 board IN2 | Uno D9 | Coil 2 |
| ULN2003 board IN3 | Uno D10 | Coil 3 |
| ULN2003 board IN4 | Uno D11 | Coil 4 |
| Stepper motor connector | ULN2003 board socket | Five-wire plug |
| 5 V adapter + | ULN2003 + terminal | Motor power |
| 5 V adapter - | ULN2003 - terminal and Uno GND | Common ground |
| Button forward | Uno D2 and GND | Move 90 degrees one way |
| Button back | Uno D3 and GND | Move 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.
| Check | Expected |
|---|---|
| Start-up | One full turn of the output shaft |
| Button forward | Quarter turn one way |
| Button back | Quarter turn the other way |
| Delay too small | Motor 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 →
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.
