Stepper motor: integration with Arduino

Stepper motor

Electric motors are increasingly in demand, among them perhaps those that work with direct current stand out, the most popular within the projects of makers with Arduino, since they provide mobility. Among them, highlight stepper motors which are used for multiple applications, especially for robotics, such as actuators, etc.

Electric cars, small autonomous robots, industrial applications for automation, repetitive movement devices, etc. The reason servo motors and stepper motors are so good for these applications is that they can perform slow or fast movements, but above all controlled. In addition, the drives are continuous for applications where many stops and starts are required with great precision.

Types of electric motors

Within electric motors the following types can be highlighted:

  • DC or DC motor: DC motors work with this type of current, as the name suggests. They can range from a few mW of power to a few MW in the most powerful and large ones, which are used for industrial applications, vehicles, elevators, conveyor belts, fans, etc. Its turning speed (RPM) and torque applied can be regulated according to the feed.
  • AC or AC motor (asynchronous and wound rotor): they work with alternating current, with a very specific rotor that works thanks to the phases that this type of current contributes to generate the rotation by means of magnetic repulsion of the electromagnet in a similar way to how DC ones do. They are very cheap and go up to several kW. They can be regulated in speed of rotation, but the regulation elements are more expensive than the DC ones. These are often used for household appliances.
  • Stepper motor- Also known as steppers, they are similar in many ways to DC, but with low spin speeds and powers. Here what stands out is the positioning of the axis, that is, the precision to put them in a specific position. Their rotation angle and speed can be controlled a lot, which is why they used to be used in floppy drives, hard drives (HDD), robots, process automation, etc.
  • Servomotor: it can be said that it is an evolution of the stepper motor, working with small powers and speeds that go up to 7000 RPM in some cases. This motor incorporates a gear reduction box and a control circuit. They have the same positioning precision as steppers and are very stable in terms of applied torque, making them ideal for some robots and industrial applications.

Stepper motors and servo motors

rotor and stator

You already know what these two types of electronic motor are, but I would like to say something more about steppers. The turn they make is not done continuously, but in small steps, hence their name. The rotor (part that rotates) has the shape of a toothed wheel, while the stator (part that does not rotate) is made up of interleaved polarized electromagnets. In this way, when one is "activated" those on its sides are not activated, which attracts the rotor tooth towards it, allowing the precise advance for which they are characterized.

Related article:
DRV8825: the driver for stepper motors

Depending on the rotor teeth, it will be possible to advance more or less in the turn. If you have more teeth, more steps are needed to complete a turn, but the steps will be shorter, so it will be a more accurate motor. If you have few teeth, the steps will be more abrupt jumps, without as much precision. Therefore, the steps that a stepper motor will have to take to complete a turn will depend on the angular steps.

Those steps angular are standardized, although you can find some motors that have non-standard pitch. The angles are usually: 1.8º, 5.625º, 7.5º, 11.25º, 18º, 45º, and 90º. To calculate how many steps a stepper motor needs to complete a full turn or turn (360º), you just need to divide. For example, if you have a 45º stepper motor, you would have 8 steps (360/45 = 8).

spin with bias (phase)

Within these motors you have the unipolar (most popular), with 5 or 6 cables, or the bipolar, with 4 cables. According to this, one or the other will be carried out polarization sequences passing current through its coils:

  • Polarization for bipolar:
Step Terminal A Terminal B Terminal C Terminal D
1 +V -V +V -V
2 +V -V -V +V
3 -V +V -V +V
4 -V +V +V -V
  • For unipolar:
Step Coil A Coil B Coil C Coil D
1 +V +V 0 0
2 0 +V +V 0
3 0 0 +V +V
4 +V 0 0 +V

The operation in both cases is the same, polarizing the coils to attract the rotor to where you want the axis to be positioned. If you want keep it in one position, you must maintain polarization for that position and voila. And if you want it to move forward, you polarize the next magnet and it will take another step, and so on ...

If you use a servo-motor, you already know that it is basically a stepper motor therefore everything said works for them too. The only thing that includes those reduction gears to obtain many more steps per turn and thus have a much higher precision. For example, you can find a motor with 8 steps per turn that if it had a 1:64 gearbox, since it means that each step of those eight is subdivided into 64 smaller steps, which would give a maximum of 512 steps per turn. That is, each step would be about 0.7º.

Related article:
L298N: module to control motors for Arduino

Also add that you should use some controller with which to control polarization, speed, etc., with, for example, H-Bridge. Some models are the L293, ULN2003, ULQ2003, etc.

Dónde comprar

You can buy it on various online sites or in specialized electronics stores. Also, if you are a beginner, you can use kits that include everything you need and even the plate Arduino UNO and manual to start experimenting and creating your projects. In these kits everything you need is included, from the motor itself, the controllers, boards, breadboard, etc.

Stepper motor example with Arduino

Arduino with stepper motor and controller

Finally, show a practical example with Arduino, using ULN2003 controller and 28BYJ-48 stepper motor. It is very simple, but it will be enough for you to begin to familiarize yourself with the operation so that you can start doing some tests and see how it behaves ...

As seen in the wiring diagram, the motor coils A (IN1), B (IN2), C (IN3) and D (IN4) have been assigned to connections 8, 9, 10, and 11 respectively on the Arduino board. On the other hand, the driver or controller board must be fed on its 5-12V pins (to GND and 5V of Arduino) with the appropriate voltage so that it in turn feeds the motor connected to the white plastic connector that has this driver or controller.

This 28BYJ-48 engine It is a unipolar type stepper motor with four coils. Therefore, to give you an idea of ​​how it works, you can send HIGH (1) or LOW (0) values ​​to the coils from the Arduino board as follows for the steps:

Step Coil A Coil B Coil C Coil D
1 HIGH HIGH LOW LOW
2 LOW HIGH HIGH LOW
3 LOW LOW HIGH HIGH
4 HIGH LOW LOW HIGH

As to sketch or code needed to program your movement, as it would be the following using Arduino IDE (modify it and experiment to test how the movement is altered):

// Definir pines conectados a las bobinas del driver
#define IN1  8
#define IN2  9
#define IN3  10
#define IN4  11

// Secuencia de pasos a par máximo del motor. Realmente es una matriz que representa la tabla del unipolar que he mostrado antes
int paso [4][4] =
{
  {1, 1, 0, 0},
  {0, 1, 1, 0},
  {0, 0, 1, 1},
  {1, 0, 0, 1}
};

void setup()
{
  // Todos los pines se configuran como salida, ya que el motor no enviará señal a Arduino
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

// Bucle para hacerlo girar
void loop()
{ 
    for (int i = 0; i < 4; i++)
    {
      digitalWrite(IN1, paso[i][0]);
      digitalWrite(IN2, paso[i][1]);
      digitalWrite(IN3, paso[i][2]);
      digitalWrite(IN4, paso[i][3]);
      delay(10);
    }
}


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.