Built-in project · Arduino Uno R3

Stepper turntable on an Arduino Uno

A photo turntable on a 28BYJ-48 and its ULN2003 board with AccelStepper: press the button and the plate turns a full circle in eight stops, flashing the camera LED at each. 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.

IntermediateRuns in your browser. Free, and no account needed.

Stepper turntable · Arduino Uno R3live0.000 s 0.00x
Hold the button
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Stepper turntable: a photo turntable on a 28BYJ-48 and its ULN2003 board,
// with AccelStepper. Press the button and it turns the plate a full circle in
// eight stops, pausing at each one while the LED fires the camera.
//
//   ULN2003  IN1 pin 8, IN2 pin 9, IN3 pin 10, IN4 pin 11, + to 5V, - to GND
//   button   pin 2 to GND, INPUT_PULLUP
//   LED      pin 13, the camera trigger (the Uno's own LED)
//
// The pins go to AccelStepper as 8, 10, 9, 11: IN1, IN3, IN2, IN4. The library
// numbers its four pins for a motor on H bridges, and that order is what makes
// its sequence walk a ULN2003's four coils round in order. Given 8, 9, 10, 11
// the motor hums and stays where it is.
//
// HALF4WIRE is half stepping: 4096 steps to a turn of the output shaft, so a
// stop every eighth of a turn is 512 steps. The plate speeds up and slows down
// for each stop, which is what keeps a real one from sliding the object on it.
// run() makes at most one step a call, so the loop never waits while the
// plate is moving.

#include <AccelStepper.h>

const int BUTTON = 2;
const int SHUTTER = 13;
const int STOPS = 8;
const long STEPS_PER_STOP = 4096 / STOPS;  // 4096 half steps to a turn

AccelStepper plate(AccelStepper::HALF4WIRE, 8, 10, 9, 11);

int stop = 0;
bool turning = false;

void setup() {
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(SHUTTER, OUTPUT);
  plate.setMaxSpeed(800);
  plate.setAcceleration(400);
  Serial.begin(115200);
  Serial.println("turntable: press the button to start a circle");
}

void photo() {
  // One digit is all eight stops need.
  Serial.print("photo ");
  Serial.write('1' + stop);
  Serial.println();
  digitalWrite(SHUTTER, HIGH);
  delay(200);
  digitalWrite(SHUTTER, LOW);
  delay(300);
}

void loop() {
  if (!turning) {
    if (digitalRead(BUTTON) == LOW) {
      turning = true;
      stop = 0;
      plate.setCurrentPosition(0);
      photo();
      plate.moveTo(STEPS_PER_STOP);
    }
    return;
  }
  if (plate.distanceToGo() != 0) {
    plate.run();
    return;
  }
  stop++;
  if (stop < STOPS) {
    photo();
    plate.moveTo((stop + 1) * STEPS_PER_STOP);
  } else {
    Serial.println("full circle: done");
    plate.disableOutputs();
    turning = false;
  }
}

Parts list

4 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

7 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 2; Pushbutton pin 1a
  • Arduino Uno R3 pin 5V; Stepper motor, 28BYJ-48 with ULN2003 pin VCC
  • Ground: Arduino Uno R3 pin GND; Pushbutton pin 2a; 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.