Stepper motor on pins 8 to 11, on an Arduino Uno
A 28BYJ-48 on its ULN2003 board with IN1 to IN4 on pins 8 to 11: the Stepper library turns the shaft one full turn one way, then back. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A 28BYJ-48 stepper on its ULN2003 board: one turn forward, one back.
//
// ULN2003 IN1 -> pin 8 IN2 -> pin 9 IN3 -> pin 10 IN4 -> pin 11
// ULN2003 + -> 5V (on the bench, the breadboard power module)
// ULN2003 - -> GND
//
// A stepper does not spin when you power it. It turns one small step each
// time the coils are switched in the right order, so the code decides exactly
// how far it goes. Through its gearbox the 28BYJ-48 takes 2048 steps for one
// turn of the output shaft.
//
// The Stepper library wants the pins as IN1, IN3, IN2, IN4: that is why the
// constructor says 8, 10, 9, 11. Given 8, 9, 10, 11 the motor hums and does
// not turn.
#include <Stepper.h>
const int STEPS_PER_TURN = 2048;
Stepper motor(STEPS_PER_TURN, 8, 10, 9, 11);
void release() {
for (int pin = 8; pin <= 11; pin++) digitalWrite(pin, LOW);
}
void setup() {
motor.setSpeed(15); // revolutions per minute; this motor manages about 15
Serial.begin(9600);
Serial.println("Mokxi Uno: stepper on pins 8 to 11");
}
void loop() {
Serial.println("one turn clockwise");
motor.step(STEPS_PER_TURN);
release();
delay(500);
Serial.println("one turn back");
motor.step(-STEPS_PER_TURN);
release();
delay(500);
}
Parts list
3 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 11; Stepper motor, 28BYJ-48 with ULN2003 pin IN4
- Arduino Uno R3 pin 10; Stepper motor, 28BYJ-48 with ULN2003 pin IN3
- Arduino Uno R3 pin 9; Stepper motor, 28BYJ-48 with ULN2003 pin IN2
- Arduino Uno R3 pin 8; Stepper motor, 28BYJ-48 with ULN2003 pin IN1
- Arduino Uno R3 pin 5V; Stepper motor, 28BYJ-48 with ULN2003 pin VCC
- Ground: Arduino Uno R3 pin GND; Stepper motor, 28BYJ-48 with ULN2003 pin GND
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.