28BYJ-48 stepper with a ULN2003
Turn the cheap 5 V geared stepper from Arduino kits through its ULN2003 board with the Stepper library.
Motors · Beginner
In a real product: Air conditioner vents (Smart home): A small geared stepper swings the louvres.
The 28BYJ-48 is the little stepper in almost every Arduino starter kit. It runs on 5 V and has a gearbox inside, so it is slow but precise: 2048 steps for one turn of its shaft. It comes with a ULN2003 driver board.
What you'll learn
- Unipolar steppers: a common wire and four coil halves
- What the ULN2003 does: switches each coil to ground for a pin
- The Stepper library, and why the pin order in its constructor matters
How it works
IN1–IN4 go to pins 8–11. The ULN2003 is a set of transistors: when an IN pin is HIGH, the matching OUT pin is connected to GND. The motor's red wire is its common, held at 5 V, so each OUT that is pulled low energises one coil half. The LEDs A–D on the board show which inputs are on.
Energising the coils in the right order steps the rotor round. The Stepper library expects the pins in the order IN1, IN3, IN2, IN4 for this motor, which gives that sequence. setSpeed(12) means 12 turns a minute, and step(n) moves n steps and returns when done: 512 steps is a quarter turn.
Try this
- Make it turn exactly once (2048 steps), then pause.
- Use half-stepping by writing the 8-step sequence yourself, for 4096 steps a turn. Write it to the pins in the order IN1, IN2, IN3, IN4: the IN1, IN3, IN2, IN4 order is only for the Stepper library's own sequence.
- Point a needle at a value: map a potentiometer to an angle and step there.
sketch.ino
// A 28BYJ-48 stepper on a ULN2003 board (IN1-IN4 on pins 8-11): quarter turns back and forth.
#include <Stepper.h>
const int STEPS_PER_TURN = 2048;
Stepper motor(STEPS_PER_TURN, 8, 10, 9, 11); // IN1, IN3, IN2, IN4
void setup() {
motor.setSpeed(12); // turns per minute
Serial.begin(9600);
}
void loop() {
Serial.println("Quarter turn clockwise");
motor.step(STEPS_PER_TURN / 4);
delay(500);
Serial.println("Quarter turn back");
motor.step(-STEPS_PER_TURN / 4);
delay(500);
}