ULN2003 board stepping its LEDs on an Arduino Uno
The green ULN2003 driver board on pins 8 to 11, with the Stepper library walking its four LEDs through the coil sequence a 28BYJ-48 turns to. The whole build, an Arduino Uno and 2 more parts, 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 parts retail for about $28. On Mokxi they're free.
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
2 parts, plus the jumper wires and a bench instrument. The parts retail for about $28; on Mokxi they're free, and so are the instruments.
How it is wired
10 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; ULN2003 stepper driver board pin IN4
- Arduino Uno R3 pin 10; ULN2003 stepper driver board pin IN3
- Arduino Uno R3 pin 9; ULN2003 stepper driver board pin IN2
- Arduino Uno R3 pin 8; ULN2003 stepper driver board pin IN1
- Arduino Uno R3 pin 5V; ULN2003 stepper driver board pin VCC
- Ground: Arduino Uno R3 pin GND; ULN2003 stepper driver board pin GND; Logic analyzer, four channels pin GND
- ULN2003 stepper driver board pin OUT1; Logic analyzer, four channels pin D0
- ULN2003 stepper driver board pin OUT2; Logic analyzer, four channels pin D1
- ULN2003 stepper driver board pin OUT3; Logic analyzer, four channels pin D2
- ULN2003 stepper driver board pin OUT4; Logic analyzer, four channels pin D3
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.