Matha Goram
Published © GPL3+

Stepping Through

This note (3rd in series) illustrates the introductory use of a stepper motor from an Arduino single board microcomputer.

BeginnerFull instructions provided30 minutes949
Stepping Through

Things used in this project

Hardware components

Elegoo Arduino UNO
×1
Elegoo 28BYJ-48 stepper motor
×1
Elegoo X113647 interface board
×1
Elegoo DuPont connection wires
×1
4xAAA battery holder
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Layout

Stepper motor test exercise layout

Schematics

Schematic

Stepper motor test exercise schematic

Code

Code snippet #1

Plain text
for (int i=0; i<=180; i+=1)// iterate through all positions from 0 to 180 degrees
  {
    myServo.write(i);      // set the shaft angle to corresponding orientation
    delay(100);            // 100 milliseconds hold for test use only
  }

Code snippet #2

Plain text
  for (int i=pwMin; i<=pwMax; i+=1) // iterate through all pulse width values from pwMin to pwMax
  {
    myServo.writeMicroseconds(i);   // set pulse width for desired angle and rotate shaft to corresponding position
    delay(5);                       // 100 milliseconds hold for test use only
  }

ElegooMotorStepper-01.ino

Arduino
A basic set of tests to drive a stepper motor directly
/*
 * ElegooMotorStepper-01.ino
 * A basic set of tests to drive a stepper motor directly
 * 2018-10-12
 * armw
 * v0.1
 * © 2018 <reza@parkcircus.org> All Rights Reserved
 *  
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.  
 * 
 * Reference:
 * https://www.arduino.cc/en/Reference/Stepper
 * Stepper(steps, pin1, pin2)             - instantiate stepper motor entity with two pins
 * Stepper(steps, pin1, pin2, pin3, pin4) - instantiate stepper motor entity with four pins
 * setSpeed(rpm)                          - set motor speed in rpm
 * step(steps)                            - turn the motor by specified steps
 * 28BYJ-48 specifications                - unipolar stepper motor
 * Coils  4 (orange, pink, yellow and blue) - 8 step control signal
 * Stride angle 5.625 degrees/64 - every step is 5.625 degrees and 64 steps to complete one rotation
 * ULN2003 driver board
 * http://www.ti.com/lit/ds/symlink/uln2003a.pdf
 * UNO  IN ULN2003A OUT   Color   Coil
 * 11   1  IN1 OUT1 16    Blue    4
 * 10   2  IN2 OUT2 15    Pink    3
 * 09   3  IN3 OUT3 14    Yellow  2
 * 08   4  IN4 OUT4 13    Orange  1
 * GND  8  GND  COM 09    Red     n/a
 * Turn sequence
 * IN1  IN2   IN3   IN4
 * 0    0     0     1
 * 0    0     1     1
 * 0    0     1     0
 * 0    1     1     0
 * 0    1     0     0
 * 1    1     0     0
 * 1    0     0     0
 * 1    0     0     1
 * Alternate library
 * http://www.airspayce.com/mikem/arduino/AccelStepper/
 * AccelStepper library for Arduino
 */

#include <Stepper.h>                // control unipolar or bipolar stepper motors

const int stepsPerRevolution = 64;  // number of steps per revolution for motor model in use
Stepper myStepper(stepsPerRevolution, 11, 10, 9, 8); // instantiate stepper motor entity

void setup()
{
  delay(1000);
}

void loop()
{
  for (int i = 10; i < 250; i = i + 10) // iterate over a range of motor speeds
  {
    myStepper.setSpeed(i);              // set motor speed in RPM; no motor movement
    myStepper.step(stepsPerRevolution); // step one revolution of stepper motor; external visible rotation depends on gears
    delay(1000);
    myStepper.step(-stepsPerRevolution);// rotate in opposite direction (-ve steps)
    delay(1000);
  }
}

Github

https://github.com/tardate/X113647Stepper

Credits

Matha Goram

Matha Goram

27 projects • 22 followers
Working with discrete electronic components for a very long time but still suffering from the occasional dry soldering results.

Comments