Biblioteca Arduino para motores de passo tipo bipolar

Arduino library for bipolar stepper motors

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

So, here I present the bipolar stepper motor library on Arduino for all bipolar type stepper motors. The library has 9 different functions that can be used to rotate and control the motor as per the requirements. The library is designed according to industrial motion control requirements. Here are some of the features of this library.

1. Controls any bipolar stepper motor

2. Controls the direction of rotation of the motor

3. Accurately controls the number of engine rotations like 1, 2, 3, 4,…..

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

5. Precisely rotates the motor to the desired angle between 0 – 360 ° with 80-100% accuracy

6. Compatible with all Arduino boards

Brief descriptions of all library functions are provided here. Some examples are given below that explain how the motor is controlled using this library. A video is also provided that shows the demonstration of these examples. Finally, the circuit that uses the L293D chip is suggested – widely used as an H-bridge driver for DC motors, as well as bipolar stepper motors.

To use this library in your Arduino sketch, simply copy the bi_polar_Stepper folder to the root directory of the Arduino library folder, such as 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 you need to specify the Arduino board pins which are used to drive the stepper motor

2) set_step_per_rev(int steps) – this function will define the number of steps needed for the stepper motor to complete 1 revolution. It means it will set the step angle (step resolution) of the motor. It is necessary to enter the motor step angle for accurate control

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

4) rotate_CW – this function will start rotating the motor clockwise. To continuously rotate the motor clockwise it is necessary to use this function in a continuous loop

5) rotate_CCW – this function will start the motor rotation in a counterclockwise direction. To turn the motor counterclockwise continuously it is necessary to use this function in a continuous loop

6) rotate(int dir) – this function will rotate the motor according to the selected direction. If direction is given as 1, the motor will rotate clockwise and vice versa

7) rotate_one_rev (internal directory) – this function will rotate the motor exactly 1 revolution in the selected direction

8) rotate_n_rev(int directory,int num) – this function will rotate the motor by the required number of rotations in the selected directions

9) rotate_x_deg(int degrees) – this function will rotate the motor to the desired angle from 0 to 360o in any direction with 80 to 100% angle accuracy

EXAMPLES

1) Rotate the engine continuously in any direction at 60 RPM

/*this program will continuously rotate the bipolar stepper motor
* with 1.8 degree step angle (200 steps/rev) at 60 RPM
* created by Ashutosh Bhatt on 12/12/16
*/
#include #define steps 200 // change these steps depending on the engine bi_polar_Stepper my_stepper_motor(8,9,10,11); internal rpm = 60; null configuration { // put your configuration 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”); } empty loop { my_step_motor.rotate_CW; }

2) Rotate the motor one turn clockwise and one turn counterclockwise continuously

/*this program will rotate the bipolar stepper motor
* with 1.8 degree step angle (200 steps/rev)
*as 1 revolution clockwise (CW) and 1 revolution
*counterclockwise (CCW) at 30 RPM continuously
* created by Ashutosh Bhatt on 12/12/16
*/
#include #define steps 200 bi_polar_Stepper my_stepper_motor(8,9,10,11); internal rpm = 30; null configuration { // put your configuration 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); } empty loop { Serial.println(“motor rotates clockwise”); my_stepper_motor.rotate_one_rev(1); delay(1000); Serial.println(“motor rotates counterclockwise”); my_stepper_motor.rotate_one_rev(0); delay(1000); }

3) Rotate the engine clockwise at 100 RPM and counterclockwise at 50 RPM continuously

/*this program will first rotate the bipolar stepper motor * with 1.8 degree step angle (200 steps/rev) * clockwise (CW) for 2 rotations at 100 RPM and then *counterclockwise (CCW) for 2 rotations at 50 RPM * continuously * created by Ashutosh Bhatt on 12/12/16 */ #include #define steps 200 bi_polar_Stepper my_stepper_motor(2,3,4,5); int i; null configuration { Serial.begin(9600); Serial.println(“Bipolar stepper motor library test program created by Ashutosh Bhatt”); my_step_motor.set_step_per_rev(steps); } empty 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 the engine 4 turns clockwise at 20 RPM and 2 turns counterclockwise at 10 RPM continuously

/*this program will first rotate the bipolar stepper motor * with 1.8 degree step angle (200 steps/rev) * 4 clockwise rotations (CW) at 20 RPM and then * 2 counterclockwise rotations (CCW) at 10 RPM * continuously * created by Ashutosh Bhatt on 12/12/16 */ #include #define steps 200 bi_polar_Stepper my_stepper_motor(2,3,4,5); int i; null configuration { Serial.begin(9600); Serial.println(“Unipolar stepper motor library test program created by Ashutosh Bhatt”); my_step_motor.set_step_per_rev(steps); } empty 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 the engine 90o clockwise and 90o counterclockwise continuously at 30 RPM

/*this program will rotate the bipolar motor * with 1.8 degree step angle (200 steps/rev) at 30 RPM for * 90 degrees CW and 90 degrees CCW continuously * created by Ashutosh Bhatt on 10/22/16 */ #include # define motor_steps 200 bi_polar_Stepper my_stepper_motor(8,9,10,11); internal rpm = 30; null configuration { // put your configuration 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 degrees back and forth”); } empty loop { my_step_motor.rotate_x_deg(90); delay(2000); my_step_motor.rotate_x_deg(270); delay(2000); }

Note:- If the stepper motor has higher current and voltage ratings then instead of L293D chip we can use L298 chip or a set of 4 separate Darlington transistors like TIP122, TIP142 etc.

Here is the summary of the above circuit arrangement.

Protótipo de controlador de motor de passo tipo bipolar

Fig. 1: Bipolar stepper motor controller prototype

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

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

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

Just watch the videos provided here for demonstration.

Circuit diagrams

Bipolar type stepper motor controller circuit diagram

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.