Stepper-based rotating stand controlled by serial dialogue
Click on the pictures to enlarge


Circuito (disegnato con Fritzing)

Circuit (designed with Fritzing)

Pannello base - Lato A
Dal punto di vista meccanico, l'assemblaggio è molto semplice: per il tavolino di base basta un riquadro di compensato o materiale simile, di circa 15cmx15cm di lato,
Il centro del tavolino sarà trovato all'incrocio delle diagonali - si trapanerà un foro da 6mm esattamente in tale punto.
L'albero dello stepper è fuori centro: infilando l'albero nel foro appena ricavato, sarà possibile tracciare il contorno dello stepper con una matita.
Poi, si taglierà un foro circolare, il più possibile aderente al bordo dello stepper, in modo tale che i due fori di fissaggio dello stepper siedano fermamente sul legno del tavolino, in modo da poterli utilizzare per fissare lo stepper al tavolino.
Servono piedini di gomma alti 10mm per consentire la luce necessaria (lo stepper sporgerà un po' al di sotto del tavolino).
Il piatto rotante sarà collegato allo stepper grazie a un Pololu Universal Aluminum Mounting Hub for 5mm Shaft.

Base panel - Side A
From the mechanical point of view, the assembly is very simple: just a square of plywood or similar material, around 15cmx15cm size, is needed for the base table.
The center of the table will be found at the crossing of the diagonals - a 6mm hole will be drilled exactly at that point.
The stepper hub is off-center: by sticking the hub into the 6mm hole, the contour of the stepper can be drawn with a pencil.
Then, a round hole as tight as possible around the stepper contour will be cut by a fretsaw, so that the two fixing holes of the stepper sit firmly on the wood of the table, so that they can be used to fix the stepper to the table. 10mm high rubber pads are needed to allow the needed clearance (the stepper will stick a little under the table).
The rotating plate will be fixed to the stepper thanks to a Pololu Universal Aluminum Mounting Hub for 5mm Shaft.

Pannello base - Lato B

Base panel - Side B

Source code


/*
 
Stepper-based rotating stand controlled by serial dialogue

Circuit and comments: 
See http://www.cesarebrizio.it/Arduino/Turntable.html
Circuit is as illustrated here:
https://www.tdegypt.com/wp-content/uploads/2017/08/stepper-motor-wiring.png
the only exception being that the sketch uses digital outputs 4 - 5 - 6 - 7
while the Fritzing diagram 
 
 created 23 Dec 2017
 modified ----
 by Cesare Brizio
 
This example code is in the public domain.

This sketch controls a rotating platform based on a stepper motor.
Stepper model is 28BYJ48, controlled via the X113647 Stepper Motor 
Driver (based on the ULN2003A IC) normally purchased with the stepper.  

The platform can rotate in both directions and is controlled via Serial Monitor 
or Tera Term.
The following commands are implemented:

R = Rotate Clockwise continuously (meaning: for several turns)
r = Rotate for 360deg; clockwise
L = Rotate Counter-clockwise continuously (meaning: for several turns)
l = Rotate for 360deg; counter-clockwise
S = Stop rotating
 
Sources of information:
Small stepper control: http://arduino-info.wikispaces.com/SmallSteppers

*/

/*-----( Import needed libraries )-----*/
#include <AccelStepper.h>

/*-----( Declare Constants and Pin Numbers )-----*/
/* NEVER PUT ; AFTER A #define statement!!!! */
// motor pins
#define motorPin1  4     // Blue   - 28BYJ-48 pin 1
#define motorPin2  5     // Pink   - 28BYJ-48 pin 2
#define motorPin3  6     // Yellow - 28BYJ-48 pin 3
#define motorPin4  7     // Orange - 28BYJ-48 pin 4
                        // Red    - 28BYJ-48 pin 5 (VCC)
                        // Blue   - 28BYJ-48 pin GND  
#define STEPS_PER_TURN 2048 // number of steps in 360deg;

int motorSpeed = 500; // High speeds (800 and above) may cause erratic behavior in 28BYJ-48
int motorAccel = 400; // As above: better avoiding extreme accelerations
int myPos = 0; // will be used to define a starting point for 360deg; rotations
int LeftTurnUp = 0; // Couple of flags to determine rotation direction
int RightTurnDown = 0; // Couple of flags to determine rotation direction
int Continuous = 0; // used below to discriminate single rotation commands
int incomingByte = 0; // for incoming serial data

/*-----( Objects for stepper control )-----*/
// Set up the stepper as 4 wire bipolar on pin 4,5,6,7
// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper(4,motorPin1,motorPin3,motorPin2,motorPin4); 

void setup()
{
  Serial.begin(9600);
  stepper.setMinPulseWidth(20); // Advisable setting to avoid that pulses from Arduino
                                // are too quick to be decoded
  stepper.setMaxSpeed(motorSpeed);
  stepper.setSpeed(motorSpeed);
  stepper.setAcceleration(motorAccel);
  // the following two lines reset "step zero" to the current position
  stepper.setCurrentPosition(stepper.currentPosition());
  stepper.runToPosition();
  Serial.println("Available commands:");
  Serial.println("R = continuous clockwise rotation");
  Serial.println("r = 360deg; clockwise rotation");
  Serial.println("L = continuous counter-clockwise rotation");
  Serial.println("l = 360deg; counter-clockwise rotation");
  Serial.println("S = stop rotation");
}

void loop()
{

  if (Serial.available() > 0) 
  {
    incomingByte = Serial.read();
    {
      if (incomingByte == 'R')
      {
        Serial.println("received «R» - activating continuous clockwise rotation");
        // The two lines that follow allow to send commands in any sequence:
        // before execution, a quick stop is performed
        stepper.stop(); // Stop as fast as possible: sets new target
        stepper.runToPosition(); // Now stopped after quickstop
        // The following couple of flags determines rotation direction
        LeftTurnUp = 1;
        RightTurnDown = 0;
        Continuous = 1; // used below to discriminate single rotation commands
        stepper.setCurrentPosition(stepper.currentPosition()); // Set step 0 "here"
        stepper.setSpeed(motorSpeed); // Previous commands have reset the speed
      } 
      
      if (incomingByte == 'L')
      {
        Serial.println("received «L» - activating continuous counter-clockwise rotation");
        // The two lines that follow allow to send commands in any sequence:
        // before execution, a quick stop is performed
        stepper.stop(); // Stop as fast as possible: sets new target
        stepper.runToPosition(); // Now stopped after quickstop
        // The following couple of flags determines rotation direction
        RightTurnDown = 1;
        LeftTurnUp = 0;
        Continuous = 1; // used below to discriminate single rotation commands
        stepper.setCurrentPosition(stepper.currentPosition()); // Set step 0 "here"
        stepper.setSpeed(motorSpeed); // Previous commands have reset the speed
      }

      if (incomingByte == 'r')
      {
        Serial.println("received «r» - activating single clockwise rotation");
        // The two lines that follow allow to send commands in any sequence:
        // before execution, a quick stop is performed
        stepper.stop(); // Stop as fast as possible: sets new target
        stepper.runToPosition(); // Now stopped after quickstop
        // The following couple of flags determines rotation direction
        LeftTurnUp = 1;
        RightTurnDown = 0;
        Continuous = 0; // used below to discriminate single rotation commands
        stepper.setCurrentPosition(stepper.currentPosition()); // Set step 0 "here"
        stepper.setSpeed(motorSpeed); // Previous commands have reset the speed
        // Since I will have to step forward 2047 steps, I store my current 
        // position as starting point of the rotation
        myPos=stepper.currentPosition();
      } 
      
      if (incomingByte == 'l')
      {
        Serial.println("received «l» - activating single counter-clockwise rotation");
        // The two lines that follow allow to send commands in any sequence:
        // before execution, a quick stop is performed
        stepper.stop(); // Stop as fast as possible: sets new target
        stepper.runToPosition(); // Now stopped after quickstop
        // The following couple of flags determines rotation direction
        RightTurnDown = 1;
        LeftTurnUp = 0;
        Continuous = 0; // used below to discriminate single rotation commands
        stepper.setCurrentPosition(stepper.currentPosition()); // Set step 0 "here"
        stepper.setSpeed(motorSpeed); // Previous commands have reset the speed
        // Since I will have to step backwards 2047 steps, I store my current 
        // position as starting point of the rotation
        myPos=stepper.currentPosition();
      }
      if (incomingByte == 'S')
      {
        Serial.println("received «S» - stopping rotation");
        // Reset the flags that determine rotation direction
        LeftTurnUp = 0;
        RightTurnDown = 0;
        stepper.stop(); // Stop as fast as possible: sets new target
        stepper.runToPosition(); // Now stopped after quickstop
      } 
    }
  }

  if (Continuous == 1) // continuous rotation 
    {
    if (LeftTurnUp == 1)  //left turn
      {
        stepper.moveTo(10000); //move many steps - more then mechanical needed
    }

    if (RightTurnDown == 1)  //right turn
      {
       stepper.moveTo(-10000); //move many steps - more then mechanical needed
    }
    stepper.run();
  }
  if (Continuous == 0) // continuous rotation 
    {
    if (LeftTurnUp == 1)  //left turn
      {
        stepper.moveTo(myPos+STEPS_PER_TURN); // 1 turn = 2048 step
    }

    if (RightTurnDown == 1)  //right turn
      {
       stepper.moveTo(myPos-STEPS_PER_TURN); // 1 turn = 2048 step
    }
  }
  stepper.run();
}