Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
    • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Arduino Library for Bipolar Type Stepper Motors

December 1, 2020 By Ashutosh Bhatt

Previously, I have given arduino library for unipolar type stepper motors. It perfectly controls speed, direction, a number of revolutions, motor angle etc all the parameters of unipolar type stepper motors. But it was for only unipolar type stepper motors. As we know the stepper motor may be bipolar type also. But this library cannot control bipolar type stepper motor. So I have decided to develop another arduino library to control bipolar type stepper motor.

So, here I present Bipolar Stepper motor library in Arduino for all bipolar type stepper motors. 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 bipolar stepper motor

2. Controls direction of rotation of motor

3. Accurately controls the 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

6. Compatible with all arduino boards

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. One video is also given that shows the demonstration of these examples. At last, the circuit is suggested that uses L293D chip – widely used as H-bridge driver for DC motors as well as bipolar stepper motors.

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

DESCRIPTION OF LIBRARY FUNCTIONS

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

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

3) set_RPM(int rpm) – this function will set the speed of motor in RPM and motor will rotate at selected 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 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 bipolar stepper motor
 * with 1.8 deg step angle (200 steps/rev) at 60 RPM
 * created by Ashutosh Bhatt on 12/12/16
*/
#include <bi_polar_Stepper.h>
#define steps 200 // change this steps as per motor
bi_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(“bipolar 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 bipolar stepper motor
 * with 1.8 deg step angle (200 steps/rev)
 * as 1 revolution clockwise (CW) and one revolution
 * counter clockwise (CCW) at 30 RPM continuously
 * created by Ashutosh Bhatt on 12/12/16
*/
#include <bi_polar_Stepper.h>
#define steps 200
bi_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(“bipolar 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 bipolar stepper motor
 * with 1.8 deg step angle (200 steps/rev)
 * clockwise (CW) for 2 revolutions at 100 RPM and then
 * counter clockwise (CCW) for 2 revolutions at 50 RPM
 * continuously
 * created by Ashutosh Bhatt on 12/12/16
*/
#include <bi_polar_Stepper.h>
#define steps 200
bi_polar_Stepper my_step_motor(2,3,4,5);
int i;
void setup()
{
  Serial.begin(9600);
 Serial.println(“Bipolar 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 bipolar 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/12/16
*/
#include <bi_polar_Stepper.h>
#define steps 200
bi_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 bipolar 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 <bi_polar_Stepper.h>
# define motor_steps 200
bi_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(“bipolar 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 L293D chip, we can use L298 chip or set of 4 separate Darlington transistors like TIP122, TIP142 etc can be used to drive stepper motors.

Here is the snap of above circuit arrangement.

Prototype of Bipolar Type Stepper Motor Controller

Fig. 1: Prototype of Bipolar Type Stepper Motor Controller

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

1) 2 phase bipolar motor with 5V, 100 RPM (MAX), 200 steps/rev (1.8o step angle)

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

Just go through the videos given here for demonstration.

 

Circuit Diagrams

Circuit-Diagram-Bipolar-Type-Stepper-Motor-Controller

Project Video

Related Articles Read More >

How to build an IR remote-operated RGB LED strip using Arduino
A Bluetooth-controlled datalogger robot
How to build an automatic watering system for plants using Arduino
wireless sensor network
Wireless Sensor Network example using Arduino

Featured Tutorials

  • Capacitive Touch Controlled Robot using X-Bee Module
  • Keypad Controlled RF based Wireless Robot
  • A Bluetooth-controlled datalogger robot
  • Keypad Controlled And Industrial Gas Monitoring Wireless Robot
  • Joystick Controlled Wireless Robot
  • CAN Protocol – Understanding the Controller Area Network Protocol

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

Recent Articles

  • How to build an IR remote-operated RGB LED strip using Arduino
  • Maxim launches automotive-grade secure authenticator for enhanced vehicle safety
  • Samsung offers compact, WiFi-enabled VRF air-conditioning systems
  • Nexperia launches industry’s first 80-V RET family for high-voltage circuits
  • The Amazing World of Robotics and its Promising Future
...

RSS EDABOARD.com Discussions

  • Rippe current rating of aluminium electrolytic capacitor is very low.
  • Start-up resistor for offline flyback suffers overvoltage..but is it OK?
  • Why disabled autoCsEnable in SPI doesn't allow CS gpio control in EFR32FG14
  • Spice correlation issue
  • Mic preamp and Tx on MAX260x

RSS Electro-Tech-Online.com Discussions

  • new to Ardunio but trying to compile
  • Any Ideas As to why circuit keeps breaking
  • 12v zvs induction heater
  • First time using MOSFETs project
  • Engine Temperature using an AD590 on the Oil Pressure Wire to the engine
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 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 | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
    • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • Digi-Key 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
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering