Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Arduino Library for Unipolar Type Stepper Motors

By Ashutosh Bhatt February 24, 2017

I was doing experiments with arduino UNO and different stepper motors. Surprisingly, I didn’t get satisfactory results. The 3 stepper motors that I have, did not work properly with arduino stepper motor library provided with the arduino IDE software. The problems were -:

• Sometimes they rotate, sometimes don’t

• They do not rotate to the exact angle that I want

• The RPM (speed) at which motor rotates, that is completely different from what is entered in program

• The motor does not rotate to the desired number of rotations or to even specified angle

So, finally, I conclude – the stepper motor library and its functions given is built in arduino IDE, are not compatible with all kind of stepper motors – especially unipolar stepper motors.

I decided to create a universal kind of arduino library for all unipolar stepper motors. My requirements are straight forward that -:

• It should control any unipolar stepper motor with 4 phase.

• It should control unipolar stepper motor with any step angle – step resolution

• It should accurately control stepper motor rotation, angle, RPM and direction

• There should be enough flexibility and facilities to control the stepper motor in any manner.

So, here I present Unipolar Stepper library in Arduino for all unipolar type stepper motors having 4 phases. The library has 9 different functions that can be used to rotate and control motor as per the requirements. The library is designed as per the industrial motion control requirements. Here are some of the features of this library -:

1.Controls any unipolar stepper motor with 4 phases.

2. Controls direction of rotation of motor

3. Accurately controls a number of revolutions of the motor like 1, 2, 3, 4,…..

4. Accurately controls motor speed in RPM with 95% accuracy

5. Accurately rotates motor to desire angle between 0 – 360o with 80-100% accuracy

The brief descriptions of all library functions are given here. Some examples are given afterward that explains how the motor is controlled using this library. There are two videos given that shows the demonstration of these examples. At last, the circuit is suggested that uses UNL2003A chip – widely used to control unipolar stepper motors.

To use this library in your arduino sketch just copy the Uni_polar_Stepper folder into the root directory of arduino library folder like C:arduino-1.6.7libraries

Description of library functions

1) Uni_polar_Stepper(int pin1, int pin2, int pin3, int pin4) – this will create an instance of Uni_polar_Stepper in the arduino sketch with stepper motor driver pins. Means one has to specify arduino board pins that are used to drive the stepper motor.

2) set_step_per_rev(int steps)   – this function will set a number of steps required by a stepper motor to complete 1 revolution. Means it will set the step angle (step resolution) of the motor. One has to enter step angle of the motor for accurate control.

3) set_RPM(int rpm) – this function will set the speed of the motor in RPM and motor will rotate at the same speed with up to 95% accuracy.

4) rotate_CW() – this function will start rotating motor clockwise. To rotate motor clockwise continuously one has to use this function in a continuous loop.

5) rotate_CCW() – this function will start rotating motor counter clockwise. To rotate motor counterclockwise continuously one has to use this function in continuous loop

6) rotate(int dir)  – this function will rotate motor as per selected direction. If direction is given as 1 then motor will rotate clockwise and vice versa

7) rotate_one_rev(int dir)   – this function will rotate motor exact 1 revolution in selected direction

8) rotate_n_rev(int dir,int num)  – this function will rotate motor required number of revolutions in selected directions

9) rotate_x_deg(int deg) – this function will rotate motor to desire angle from 0 – 360o in either direction with 80 – 100% angle accuracy

EXAMPLES

1) Rotate motor continuously in any one direction at 60 RPM

/*this program will continuously rotate 4-phase unipolar stepper motor
 * with 1.8 deg step angle (200 steps/rev) at 60 RPM
 * created by Ashutosh Bhatt on 12/10/16
 
*/
#include <Uni_polar_Stepper.h>
#define steps 200 // change this steps as per motor 
Uni_polar_Stepper my_step_motor(8,9,10,11);
int rpm = 60;
 
void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600); 
 Serial.println(“Unipolar stepper motor library test program”);
 my_step_motor.set_step_per_rev(steps);
 my_step_motor.set_RPM(rpm);
  Serial.println(“motor rotates clockwise”); 
}
 
void loop() 
{
   my_step_motor.rotate_CW(); 
}

2) Rotate motor one revolution clockwise and one revolution counter clockwise continuously/*this program will rotate 4-phase unipolar stepper motor

* with 7.5 deg step angle (48 steps/rev) 
 * as 1 revolution clockwise (CW) and one revolution 
 * counter clockwise (CCW) at 30 RPM continuously
 * created by Ashutosh Bhatt on 12/10/16
 
*/
#include <Uni_polar_Stepper.h>
#define steps 48
 
Uni_polar_Stepper my_step_motor(8,9,10,11);
 
int rpm = 30;
 
void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600); 
 Serial.println(“Unipolar stepper motor library test program created by Ashutosh Bhatt”);
 my_step_motor.set_step_per_rev(steps);
 my_step_motor.set_RPM(rpm); 
}
 
void loop() 
{
   Serial.println(“motor rotates clockwise”); 
   my_step_motor.rotate_one_rev(1);
   delay(1000);
   Serial.println(“motor rotates anti-clockwise”);  
   my_step_motor.rotate_one_rev(0);
   delay(1000);
}

3) Rotate motor clockwise at 100 RPM and counter clockwise at 50 RPM continuously

/*this program will first rotate 4-phase unipolar stepper motor
 * with 7.5 deg step angle (48 steps/rev) 
 * clockwise (CW) for some revolutions at 100 RPM and then 
 * counter clockwise (CCW) for some revolutions at 50 RPM
 * continuously
 * created by Ashutosh Bhatt on 12/10/16

*/

#include <Uni_polar_Stepper.h>
#define steps 48
 
Uni_polar_Stepper my_step_motor(2,3,4,5);
 
int i;
 
void setup() 
{
  Serial.begin(9600); 
 Serial.println(“Unipolar stepper motor library test program created by Ashutosh Bhatt”);
 my_step_motor.set_step_per_rev(steps);
  
}
 
void loop() 
{
  my_step_motor.set_RPM(100);
  for(i=0;i<100;i++) my_step_motor.rotate(1);
  delay(2000);
  my_step_motor.set_RPM(50);
  for(i=0;i<100;i++) my_step_motor.rotate(0); 
  delay(2000); 
}

4) Rotate motor 4 revolutions clockwise at 20 RPM and 2 revolutions counter clockwise at 10 RPM continuously

/*this program will first rotate 4-phase unipolar stepper motor
 * with 1.8 deg step angle (200 steps/rev) 
 * 4 revolutions clockwise (CW)  at 20 RPM and then 
 * 2 revolutions counter clockwise (CCW) at 10 RPM
 * continuously
 * created by Ashutosh Bhatt on 12/10/16
*/
#include <Uni_polar_Stepper.h>
#define steps 200
 
Uni_polar_Stepper my_step_motor(2,3,4,5);
 
int i;
 
void setup() 
{
  Serial.begin(9600); 
 Serial.println(“Unipolar stepper motor library test program created by Ashutosh Bhatt”);
 my_step_motor.set_step_per_rev(steps);
  
}
 
void loop() 
{
  my_step_motor.set_RPM(20);
  my_step_motor.rotate_n_rev(1,4); 
  delay(2000);
  my_step_motor.set_RPM(10);
  my_step_motor.rotate_n_rev(0,2); 
  delay(2000); 
}

5) Rotate motor 90o clockwise and 90o anticlockwise continuously at 30 RPM

/*this program will rotate 4-phase unipolar motor
 * with 1.8 deg step angle (200 steps/rev) at 30 RPM to
 * 90 deg CW and 90 deg CCW continuously
 * created by Ashutosh Bhatt on 22/10/16
*/
#include <Uni_polar_Stepper.h>
# define motor_steps 200
Uni_polar_Stepper my_step_motor(8,9,10,11);
 
int rpm = 30;
 
void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(9600); 
 Serial.println(“Unipolar stepper motor library test program”);
 my_step_motor.set_step_per_rev(motor_steps);
 my_step_motor.set_RPM(rpm);
  Serial.println(“motor rotates 90 deg back and forth”); 
}
 
void loop() 
{
   my_step_motor.rotate_x_deg(90);
   delay(2000);
   my_step_motor.rotate_x_deg(270); 
   delay(2000);
}

Note:- If the stepper motor is of higher current and voltage ratings then instead of UNL2003A chip, set of 4 separate Darlington transistors like TIP122, TIP142 etc can be used to drive stepper motors.

The given library and example programs along with above circuit are tested with following stepper motors.

1) 4 phase unipolar motor with 12V, 120 RPM (MAX), 48 steps/ rev (7.5o step angle)

2) 4 phase unipolar motor with 5V,60 RPM (MAX), 200 steps/rev (1.8o step angle)

3) 4 phase unipolar motor with 5V, 50 RPM (MAX), 400 steps/rev (0.9o step angle)

Here is the snap of circuit arrangement.

Prototype of Arduino based Unipolar Type Stepper Motor Controller

Fig. 1: Prototype of Arduino based Unipolar Type Stepper Motor Controller

Just go through the videos given here for demonstration.

Circuit Diagrams

Circuit-Diagram-Arduino-Based-Unipolar-Type-Stepper-Motor-Controller

Project Video


Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Snooping Around is All
  • mosfet driver problem in regeneration mode
  • Industrial Relay Board Design for Motorcycle Use
  • connector model question
  • ADEM III ECM — No CAN Signal & Power Supply Issue

RSS Electro-Tech-Online.com Discussions

  • Sump pit water alarm - Kicad 9
  • Pic18f25q10 osccon1 settings swordfish basic
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe