Arduino Stepper Motor Controlling

Author : Dinesh Kumar Wickramasinghe

Introduction

I found a stepper motor from a broken printer and I was thinking how to control this. Controlling a stepper motor is not easy as controlling a simple DC motor. Finally I came to a conclusion to use my Arduino board to control the stepper motor. Arduino IDE has a special library called "Stepper" and using this library, we can easily control a stepper motor. This tutorial is about controlling stepper motors with Arduinio.

Basically there are two types of Stepper motors. Those are Unipolar and Bipolar I found that my stepper motor was a Unipolar type one by looking at the power terminals.

Here are two images of Unipolar and Bipolar motors.

Unipolar Stepper Motor
Unipolar Stepper Motor

The unipolar stepper motor operates with one winding with a center tap per phase. Each section of the winding is switched on for each direction of the magnetic field.


Bipolar Stepper Motor
Bipolar Stepper Motor

With bipolar stepper motors there is only a single winding per phase. The driving circuit needs to be more complicated to reverse the magnetic pole, this is done to reverse the bipolar stepper motor - circuit specialists blogcurrent in the winding.

The appearance of both type of motors are looks similar sometime. So you need to check the power terminals or read the manufacturer instructions

Controlling Stepper Motors

To control these two types of motors, You need two types of digital ICs

Motor Type IC To Use
Unipolar Stepper Motor ULN2004
Bipolar Stepper Motor SN754410
Schematic for Unipolar Stepper Motors
Unipolar Stepper Motor Schematic

Please note that the power supply for VCC1 is depending on the power of your stepper motor. For example, the stepper motor you are using is 9V one, then VCC should be DC 9V. This is common for the Bipolar stepper motor as well.

Schematic for Bipolar Stepper Motors
Bipolar Stepper Motor Schematic

Since my motor was a Unipolar one, I had to purchase a ULN2004A IC. The price of this IC was less than 1$. Here is my setup.

Stepper Motor Setup
Source Code

For both Unipolar and Bipolar stepper motors, below source code will work. You can control the speed of the motor using the potentiometer.


/*
 Stepper Motor Control - speed control

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.
 A potentiometer is connected to analog input 0.

 The motor will rotate in a clockwise direction. The higher the potentiometer value,
 the faster the motor speed. Because setSpeed() sets the delay between steps,
 you may notice the motor is less responsive to changes in the sensor value at
 low speeds.

 Created 30 Nov. 2009
 Modified 28 Oct 2010
 by Tom Igoe

 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}
                    

Hope you enjoyed this tutorial. Please note that the schematic and the source code extracted from the official Arduino web site. Here is the link of the original tutorial. Arduino Stepper Motor Controlling

Here is the video of my final project

If you have any comments of questions regarding this project, Please add them below comments section.

Here are some good readings to improve your knowledge more.

Have a nice day!!

Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : Nick
Added Date :4/8/2019 11:47:58 AM
Hello, Thanks for the post.

 

Similar Projects

Go Top