Arduino projects

Stepper motors and motors Arduino

Stepper motors and motors Arduino 28BYJ-48 with driver ULN2003

In this article, we will talk about stepper motors in Arduino projects using the very popular 28BYJ-48 model as an example. Just like servos, stepper motors are an extremely important element of automated systems and robotics. They can be found in many devices nearby: from a CD drive to a 3D printer or a robotic manipulator. In this article, you will find a description of the stepper motor operation diagram, an example of connecting to Arduino using ULN2003-based drivers, and example sketches using the standard Stepper library.

Stepper motor – operating principle

A stepper motor is a motor that moves its shaft depending on the steps and direction specified in the microcontroller program. Such devices are most often used in robotics, printers, manipulators, various machines and other electronic devices. A big advantage of stepper motors over continuous rotation motors is the provision of precise angular positioning of the rotor. Stepper motors also have the ability to quickly start, stop, and reverse.

The stepper motor ensures the rotor rotates at a given angle with the corresponding control signal. Thanks to this, it is possible to control the position of the mechanism units and reach a given position. The engine operates as follows: there is a row of magnets and several coils in the central shaft. When power is supplied, a magnetic field is created that affects the magnets and makes the shaft rotate. Parameters such as the rotation angle (steps), direction of movement are set in the program for the microcontroller.

Simplified animated diagrams of how a stepper motor works

Main types of stepper motors:

  • Variable magnet motors (rarely used);
  • Permanent magnet motors;
  • Hybrid motors (more complex to manufacture, more expensive, but are the most common type of stepper motors).

Where to buy stepper motor

The simplest engines Options on AliExpress:

Stepper Motor Nema17 42BYGH 1.7A (17HS4401-S) for 3D Printer Set of 5 stepper motors ULN2003 28BYJ-48 with driver boards for Arduino Stepper Motor with Driver Module 5V Stepper Motor 28BYJ-48 + ULN2003
Another Stepper Motor Option for Arduino 28BYJ-48 5V 4 Phase DC Motor + ULN2003 Drive Test Board Set of three Nema17 Stepper Motor 42BYGH 1.7A (17HS4401) for 3D printer AliExpress.com Product – 3D Printer Parts StepStick A4988 DRV8825 Stepper Motor Driver With Heat sink Carrier Reprap RAMPS 1.4 1.5 1.6 MKS GEN V1.4 board

Driver for stepper motor control

The driver is a device that connects the controller and the stepper motor. The most commonly used drivers for controlling a bipolar stepper motor are the L298N and ULN2003.

Operating the motor in bipolar mode has several advantages:

  • 40% increase in torque compared to unipolar motors;
  • Possibility of using motors with any phase winding configuration.

But a significant disadvantage of the bipolar mode is the complexity of the driver itself. The unipolar drive driver requires only 4 transistor keys, while a more complex circuit is required to ensure the operation of the bipolar drive driver. Different actions must be performed with each winding separately – connecting to a power source, disconnecting. A bridge circuit with four keys is used for such switching.

 Stepper Motor Driver Based on L298N

This bridge driver controls a motor with a current of up to 2 A and a supply of up to 46 V. The module based on the L298N driver consists of the L298N chip, a cooling system, terminal blocks, connectors for connecting signals, a voltage stabilizer and protective diodes.

Stepper Motor Driver ULN2003

Stepper motors with driver modules based on ULN2003 are frequent guests in Arduino workshops due to their low cost and availability. As a rule, you have to pay for this with not very high reliability and accuracy.

Other drivers

There is another type of drivers – STEP/DIR drivers. These are hardware modules that operate via the STEP/DIR protocol to communicate with the microcontroller. STEP/DIR drivers expand the capabilities:

  • They allow to stabilize phase currents;
  • Possibility of setting microstepping mode;
  • Ensuring protection of the key from short circuit;
  • Overheating protection;
  • Optical isolation of control signal, high immunity to interference.

STEP/DIR drivers use 3 signals:

  • STEP – a pulse that initiates rotation by a step/part of a step depending on the mode. The frequency of the pulses will determine the rotation speed of the engine.
  • DIR – a signal that specifies the direction of rotation. Usually, when a high signal is given, rotation is performed clockwise. This type of signal is formed before the STEP pulse.
  • ENABLE – permit/prohibit the driver operation. Using this signal, you can stop the engine in the mode without holding current.

One of the most inexpensive STEP/DIR drivers is the TB6560-V2 module. This driver provides all the necessary functions and modes.

Connecting a Stepper Motor to Arduino

The connection will be considered using the example of a 28BYj-48 unipolar motor and L298 and ULN2003 drivers. Arduino Uno will be used as a board.

Another version of the circuit using L298:

The connection diagram based on ULN2003 is shown in the figure below. The control outputs from the driver IN1-IN4 are connected to any digital contacts on the Arduino. In this case, digital contacts 8-11 are used. The power supply is connected to 5V. It is also advisable to use a separate power source for the motor so that the Arduino board does not overheat.

Connecting a stepper motorSchematic diagram of the connection.Schematic diagram of the stepper motor connection

Another diagram of connecting a bipolar stepper motor Nema17 via the L298 driver looks like this.

Overview of the main models of stepper motors for arduino

Nema 17 is a bipolar stepper motor, which is most often used in 3D printers and CNC machines. The 170xHSxxxA series of motors is universal.

Main engine characteristics:

  • The angular step is 1.8°, that is, there are 200 steps per 1 revolution;
  • Engine – two-phase;
  • Operating temperatures from -20C to 85C;
  • Nominal current 1.7A;
  • Holding moment 2.8 kg x cm;
  • Equipped with a 42 mm flange for easy and high-quality installation;
  • High torque – 5.5 kg x cm.

28BYJ-48 is a unipolar stepper motor. It is used in small robot projects, servo drives, radio-controlled devices.

Engine specifications:

  • Nominal power supply – 5V;
  • 4-phase motor, 5 wires;
  • Number of steps: 64;
  • Step angle 5.625°;
  • Rotation speed: 15 revolutions per second
  • Torque 450 g/cm;
  • DC resistance 50Ω ± 7% (25℃).

Description of the library for working with a stepper motor

The Arduino IDE development environment has a standard library Strepper.h for writing stepper motor programs. The main functions in this library are:

  • Stepper(number of steps, pin numbers). This function creates a Stepper object, which corresponds to the motor connected to the Arduino board. The argument is the pins on the board to which the motor is connected, and the number of steps that are taken to make a full rotation around its axis. Information on the number of steps can be found in the documentation for the motor. Instead of the number of steps, the angle that makes up one step can be specified. To determine the number of steps, divide 360 ​​degrees by this number.
  • Set Speed(long rpms) – function that specifies the rotation speed. The argument is a positive integer that specifies the number of revolutions per minute. It is set after the Step() function.
  • Step(Steps) – rotation by the specified number of steps. The argument can be either a positive number – rotation of the motor clockwise, or a negative number – counterclockwise.

Example sketch for control

In the Stepper.h library set of examples there is a program stepper_oneRevolution, in which all parameters for the stepper motor are set – the number of steps, speed, rotation.

#include <Stepper.h>

const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 8,9,10,11); //connect to pins 8…11 on Arduino

void setup() {

myStepper.setSpeed(60); //setting the rotor speed

Serial.begin(9600);

}

void loop() {

//The function waits for a command to be received, converts the text, and sends a signal to the motor to rotate it by the specified number of steps.

Serial.println("Move right"); //clockwise

myStepper.step(stepsPerRevolution);

delay(1000);

Serial.println("Move left"); //counterclockwise

myStepper.step(-stepsPerRevolution);

delay(1000);

}

Conclusion

In this article, we learned what a stepper motor is, how to connect it to an Arduino, and what a stepper motor driver is. We also looked at an example of writing a sketch using the built-in Stepper library. As you can see, there is nothing particularly complicated in working with stepper motors, and we recommend that you definitely experiment on your own and try to include it in your Arduino projects .

Back to top button