Project tutorial
Stepper-Based Rotating Stand Controlled by Serial Dialogue

Stepper-Based Rotating Stand Controlled by Serial Dialogue © GPL3+

A rotating platform based on a stepper motor 28BYJ48, controlled via the X113647 stepper motor driver by serial dialogue.

  • 2,999 views
  • 7 comments
  • 9 respects

Components and supplies

28BYJ48 stepper motor
×1
X113647 Stepper Motor Driver
×1
Pololu Universal Aluminum Mounting Hub for 5mm Shaft
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
Wooden base 15cm x 15cm
×1
rubber pads
×4

Necessary tools and machines

fretsaw
drill with 6mm bit for wood

About this project

Full story here: http://www.cesarebrizio.it/Arduino/Turntable.html

This project is about 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

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.

Sources of information:

Small stepper control: http://arduino-info.wikispaces.com/SmallSteppers

Actually I used 4 different pins, yet the circuit illustration below reproduces accurately the connections. Looking at the photo above (Red wire from Arduino replaces "Pink"):

#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;

Code

The full sketch in ArduinoArduino
A full description of the software with comments
/*
 
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 mechanically needed
    }

    if (RightTurnDown == 1)  //right turn
      {
       stepper.moveTo(-10000); //move many steps - more then mechanically 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();
} 

Schematics

Fritzing Schematics
The full circuit made in Fritzing
Tn stepper motor wiring sfnaiskuks

Comments

Similar projects you might like

Clap Controlled Car

Project showcase by Team Clara & Jone

  • 1,290 views
  • 0 comments
  • 3 respects

Hand Gesture Controlled Robot

Project tutorial by Mayoogh Girish

  • 54,941 views
  • 78 comments
  • 65 respects

Gesture Controlled Trainable Arduino Robot Arm via Bluetooth

Project tutorial by KureBas Robotics

  • 13,564 views
  • 43 comments
  • 117 respects

Wi-Servo: Wi-Fi Browser Controlled Servomotors

Project tutorial by Igor Fonseca Albuquerque

  • 12,923 views
  • 3 comments
  • 17 respects

2WD Voice Controlled Robot with Arduino and BitVoicer Server

Project tutorial by Marcio Tamagushi

  • 10,857 views
  • 11 comments
  • 37 respects
Add projectSign up / Login