Remote stepper on an Arduino Uno
An IR receiver on pin 12 and a 28BYJ-48 on its ULN2003 board: VOL+ turns the shaft a quarter turn and VOL- turns it back. The whole build, an Arduino Uno and 3 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.
Intermediate 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.
// Remote stepper: VOL+ and VOL- on the IR remote turn a stepper motor.
//
// IR receiver OUT -> pin 12, GND -> GND, VCC -> 5V
// ULN2003 board IN1 -> pin 8, IN2 -> pin 9, IN3 -> pin 10, IN4 -> pin 11
// + -> 5V, - -> GND
//
// Each press of VOL+ turns the shaft a quarter turn clockwise, and VOL- a
// quarter turn back. The 28BYJ-48 takes 2048 full steps for one turn of its
// output shaft, so a quarter turn is 512 steps.
//
// The Stepper library wants the pins as IN1, IN3, IN2, IN4: that is why the
// constructor below says 8, 10, 9, 11. Given 8, 9, 10, 11 the motor hums and
// does not turn.
#include <IRremote.hpp>
#include <Stepper.h>
const int RECEIVER_PIN = 12;
const int STEPS_PER_TURN = 2048;
const int QUARTER = STEPS_PER_TURN / 4;
Stepper motor(STEPS_PER_TURN, 8, 10, 9, 11);
void release() {
// Let the coils go between moves, so the driver stays cool.
for (int pin = 8; pin <= 11; pin++) digitalWrite(pin, LOW);
}
void setup() {
Serial.begin(9600);
IrReceiver.begin(RECEIVER_PIN, ENABLE_LED_FEEDBACK);
motor.setSpeed(15);
Serial.println("Mokxi Uno: remote stepper. VOL+ and VOL- turn the shaft.");
}
void loop() {
if (!IrReceiver.decode()) return;
bool repeat = IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT;
uint8_t command = IrReceiver.decodedIRData.command;
IrReceiver.resume();
if (repeat) return;
if (command == 0x15) {
Serial.println("VOL+: a quarter turn clockwise");
motor.step(QUARTER);
release();
} else if (command == 0x07) {
Serial.println("VOL-: a quarter turn back");
motor.step(-QUARTER);
release();
} else {
Serial.print("button 0x");
Serial.print(command, HEX);
Serial.println(" does nothing here");
}
}
Parts list
5 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
8 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 12; Infrared receiver, VS1838B pin OUT
- 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; Infrared receiver, VS1838B pin VCC
- Ground: Arduino Uno R3 pin GND; Stepper motor, 28BYJ-48 with ULN2003 pin GND; Infrared receiver, VS1838B pin GND
- Infrared receiver, VS1838B pin IR; Infrared remote, 21 buttons pin IR
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.