Application examples of a stepper motor driver with analog input. Arduino and Nema stepper motor


Proportional stepper motor control

The device described below allows you to control a unipolar stepper motor type SDH 1.8/40 and similar. Electric scheme fundamental block control is shown in Fig. 1. It is based on the ATmega 8 microcontroller operating from a built-in clock generator at a frequency of 2 MHz. Logic elements of microcircuits DD2, DD3 of type SN75452 (Russian analogue - K155LA18) were used as keys that switch the windings of the stepper motor M1. These are microcircuits - increased power with open collector output.

The block supports proportional and discrete motor control. In proportional control mode - the angle of rotation of the motor rotor is set variable resistor ohm R1. In discrete control mode, the motor rotation “left”, “right”, “stop” is carried out by buttons S1 and S2. In addition, in the circuit you can select a step or half-step operating mode, as well as the motor rotation speed.
By setting jumper X4, proportional control is selected, and in its absence, discrete control is selected. Jumper X5 determines the step and half-step mode of operation of the motor. All these operating modes are initialized only when the circuit is turned on or the microcontroller is reset. Therefore, the necessary jumpers must be installed before turning on the power. The microcontroller uses two ADC channels. A trimming resistor R3 is connected to the input of one of them - ADC5 (28 leg). With its help, the engine rotation speed is adjusted in any operating mode of the circuit.
In proportional control mode, another ADC channel is used - ADC4 (27th leg). A variable resistor R1 is connected to its input through the integrating circuit R2, C1, which sets the angle of rotation of the motor rotor. The ADC operating speed in this control program carries out conversions with 8-bit precision. Therefore, the position of the handle of the variable resistor R1 is conventionally divided into 255 steps by the controller program. After turning on the power, the program calibrates the rotor position of the stepper motor. To do this, before starting work, the command “motor rotation to the left” is automatically executed until the flag attached to the motor rotor “reaches” the limit sensor (optocoupler) VT1, HL1. When a signal is received from sensor VT1, the program resets the register-counter of the number of engine steps, measures the voltage at the output of variable resistor R1, converts it to digital code in the range from 0 to 255, writes it to the high byte of the ADC conversion result register (this is the number of steps of the variable resistor R1), and then compares it with the contents of the motor step counter register. If the number of steps of resistor R1 is greater than the steps of motor M1, then the command is issued: “motor rotation to the right.” In this case, with each rotor step, the motor step counter is incremented and compared with the number in the ADC register (steps of resistor R1). When the number of motor steps becomes equal to the number in the ADC register, the “stop” command is executed. By turning the knob of resistor R1 “to the left”, the level decreases DC voltage at the ADC input. In this case, the number in the ADC conversion result register will become less than the current value of the step counter register. In this case, the command is issued: “motor rotation to the left.” With each motor step, the motor step counter register is decremented until the numbers in both registers are equal. Thus, by rotating the handle of variable resistor R1, the motor rotor rotates in the same direction and by the same number of steps.
I note that the proposed motor makes one revolution of 360° in 200 steps (i.e., one step is 1.8 degrees). Therefore, in this circuit, in 255 conventional steps from the variable resistor R1, the motor rotor will make more than one revolution and rotate through an angle of 459°. Therefore, to limit the angle of rotation of the motor, a limit sensor (optocoupler) is used for the extreme right position of the rotor. It is made on elements VT2, HL2. To more accurately copy the angle of rotation of the variable resistor knob with the motor rotor, it is necessary to install a limiting resistor Rlim. Its value should be carefully selected (within the range from 1 to 3 kOhm) in the gap of the resistance output R1 connected to “+5 V”.
The control program provides a function for recalibrating the position of the motor rotor during operation of the device. For example, if the rotor steps slip for any reason (the engine is overloaded, caught on something, etc.), you can turn the knob of the variable resistor R1 to the extreme left position and wait 2 - 3 seconds. In this case, the position of the rotor flag is checked using the optical sensor of the extreme left position VT1. If the flag does not enter the sensor response zone, it means that during operation there was a shift in the steps of the rotor of the motor M1 relative to the steps of the resistor R1. In this case, the system recalibration program is launched and device operation is restored.
For the circuit to operate in proportional control mode, an optical sensor for the extreme left position and calibration VT1 is required. The extreme right position sensor VT2 can be omitted if there is no need to limit the rotor position when rotating to the right. But, then, you need to connect pin 14 of the microcontroller to +5 V.
With proportional motor control in half-step mode, the rotor rotates from 0° to 230°. The engine power decreases, but the smoothness increases. This must be taken into account when choosing this operating mode.
In discrete control mode, rotation “to the right” is carried out by button S1, rotation “to the left” - by button S2. If no buttons are pressed, the stop command is executed. The engine calibration program and variable resistor R1 are not used in this mode. Optical sensors VT1, HL1 and VT2, HL2 work as limiters of the extreme positions of the M1 motor rotor. If rotation limitation is not required, then these optocouplers can be omitted. But in this case, it is necessary to solder pins 14, 15 of the microcontroller to +5V.
If it is necessary to control the operation of the stepper motor by other (external) devices, the circuit provides special outputs on the high pins of port D of the microcontroller. A short-term rectangular pulse is generated at pin PD7 “step” with each step of the motor (can be useful for an external step counter). Pin PD6 “rewers” ​​- engine reverse signal (log. 0 - rotation to the right, logic 1 - rotation to the left). When resetting (resetting) the program counter - the register of the number of steps, a short-term “reset” pulse is generated at pin PD5. These outputs also operate in proportional control mode.
The control program for the microcontroller is written in Assembly language. The firmware file is attached. In addition, it is necessary to program fuses: CKSEL0=0, CKSEL1=1, CKSEL2=0, CKSEL3=0, SUT0=0, SUT1=1, SKOPT=1.


The printed circuit board of the control unit is shown in Fig. 2. It is made of one-sided foil fiberglass laminate with dimensions of 42 × 58 mm. The attached file with the .lay extension contains a drawing for the “laser-iron” board manufacturing technology. Arrangement of circuit elements on printed circuit board shown in Figure 3.

Controlling a stepper motor using an Arduino board.

In this article we continue to deal with the topic of stepper motors. Last time we connected a small 28BYJ-48 (5V) motor to the Arduino NANO board. Today we will do the same thing, but with a different motor - NEMA 17, 17HS4402 series and a different driver - A4988.

The NEMA 17 stepper motor is a high torque bipolar motor. Can rotate a specified number of steps. In one step it makes a rotation of 1.8°, respectively full turn 360° is carried out in 200 steps.
Bipolar motor has two windings, one in each phase, which is reversed by the driver to change the direction of the magnetic field. Accordingly, four wires come from the motor.

This motor is widely used in CNC machines, 3D printers, scanners, etc.
It will be controlled using an Arduino NANO board.

This board is capable of producing a voltage of 5V, while the motor operates at a higher voltage. We chose a 12V power supply. So we need an additional module - a driver capable of controlling more high voltage through low-power Arduino pulses. The A4988 driver is perfect for this.

Stepper motor driver A4988.

The board is based on the A4988 chip from Allegro - a bipolar stepper motor driver. The A4988 features adjustable current, overload and overheat protection, and the driver also has five microstepping options (up to 1/16th step). It operates from 8 - 35 V and can provide current up to 1 A per phase without a heatsink or additional cooling ( additional cooling necessary when supplying a current of 2 A to each winding).

Characteristics:

Model: A4988;
supply voltage: from 8 to 35 V;
possibility of setting the step: from 1 to 1/16 of the maximum step;
logic voltage: 3-5.5 V;
overheat protection;
maximum current per phase: 1 A without radiator, 2 A with radiator;
distance between rows of legs: 12 mm;
board size: 20 x 15 mm;
driver dimensions: 20 x 15 x 10 mm;
radiator dimensions: 9 x 5 x 9 mm;
weight with radiator: 3 g;
without radiator: 2 g.

To operate the driver, you need logic level power (3 - 5.5 V) supplied to the VDD and GND pins, as well as motor power (8 - 35 V) to the VMOT and GND pins. The board is very vulnerable to power surges, especially if the supply wires are longer than a few centimeters. If these jumps exceed the maximum permissible value(35 V for A4988), then the board may burn out. One way to protect the board from such surges is to install a large (at least 47 uF) electrolytic capacitor between the power pin (VMOT) and ground close to the board.
Connecting or disconnecting a stepper motor while the driver is turned on may damage the motor!
The selected motor takes 200 steps per full 360° rotation, which corresponds to 1.8° per step. A microstepping driver such as the A4988 allows for increased resolution by being able to control intermediate steps. For example, running a motor in quarter-step mode will give a 200-step-per-rev motor 800 microsteps when used. different levels current
The resolution (step size) is set by combinations of switches on the inputs (MS1, MS2, and MS3).

MS1 MS2 MS3 Microstep resolution
Short Short Short Full step
High Short Short 1/2 step
Short High Short 1/4 step
High High Short 1/8 step
High High High 1/16 step

Each pulse at the STEP input corresponds to one microstep of the motor, the direction of rotation of which depends on the signal at the DIRECTION pin. The STEP and DIRECTION pins are not pulled to any specific internal voltage, so they should not be left floating when creating applications. If you just want to rotate the motor in one direction, you can connect DIR directly to VCC or GND. The chip has three different inputs to control the power state: RESET, SLEEP and ENABLE. The RESET pin floats, if you do not need to use it, you should connect it to the adjacent SLEEP pin on the PCB to power it high level and turn on the board.

Connection diagram.

We used this power supply (12V).

For ease of connection to the Arduino UNO board, we used a part we made ourselves. The plastic case is printed on a 3D printer, with contacts glued to it.

Also, we used the following set of wires, some of them have a contact on one end, a pin on the other, others have contacts on both sides.

We connect everything according to the diagram.

Then we open the program development environment for Arduino and write a program that rotates the motor first in one direction by 360°, then in the other.

/*Program for rotating a NEMA 17 stepper motor, 17HS4402 series + A4988 driver. First the motor makes a full revolution in one direction, then in the other */

const int pinStep = 5;


const int pinDir = 4;


const int move_delay = 3;

//steps per full revolution


void setup()
{

pinMode(pinStep, OUTPUT);
pinMode(pinDir, OUTPUT);


digitalWrite(pinDir, LOW);
}


void loop()
{

digitalWrite(pinDir, HIGH);

for(int i = 0; i< steps_rotate_360; i++)
{
digitalWrite(pinStep, HIGH);
delay(move_delay);
digitalWrite(pinStep, LOW);
delay(move_delay);
}

delay(move_delay*10);


digitalWrite(pinDir, LOW);

for(int i = 0; i< steps_rotate_360; i++)
{
digitalWrite(pinStep, HIGH);
delay(move_delay);
digitalWrite(pinStep, LOW);
delay(move_delay);
}

delay(move_delay*10);
}

If we want the motor to simply constantly rotate in one direction or another, then we can connect the DIRECTION driver contact to ground (clockwise rotation) or power (counterclockwise) and upload the following simple program to the Arduino:

/*Program for rotating a NEMA 17 stepper motor, 17HS4402 series + A4988 driver. The program sets the motor in motion.
By default, rotation occurs clockwise, since the DIRECTION pin of the driver is connected to ground. If you connect it to a 5V power supply, then
the motor rotates counterclockwise*/
/*integer constant storing the number of the Arduino digital pin that supplies the Step signal to the driver. Each impulse from this contact is a movement of the motor one step*/

const int pinStep = 5;

//time delay between motor steps in ms
const int move_delay = 3;

/*Function in which all program variables are initialized*/
void setup()
{
/*set the Step contact to output mode, that is, it outputs voltage*/
pinMode(pinStep, OUTPUT);
//set the initial mode
digitalWrite(pinStep, LOW);
}

/*Loop function in which the behavior of the program is specified*/
void loop()
{
/*after a specified delay, the motor moves one step*/
digitalWrite(pinStep, HIGH);
delay(move_delay);
digitalWrite(pinStep, LOW);
delay(move_delay);
}

All this we considered was the stepper mode of the motor, that is, 200 steps per full revolution. But, as already described, the motor can operate in 1/2, 1/4, 1/8, 1/16 step modes, depending on what combination of signals is supplied to the driver contacts MS1, MS2, MS3.
Let's practice with this, connect these three contacts to the Arduino board, according to the diagram, and upload the program code.

Code of a program that demonstrates all five modes of motor operation, rotating the motor in one direction and the other by 200 steps in each of these modes.

/*Program for rotating a NEMA 17 stepper motor, 17HS4402 series + A4988 driver. The program alternates between step modes: full step, 1/2, 1/4, 1/8, 1/16 steps, with each of them the motor rotates 200 steps in one direction, then in the other */
/*integer constant storing the number of the Arduino digital pin that supplies the Step signal to the driver. Each impulse from this contact is a movement of the motor one step*/

const int pinStep = 5;

/*integer constant storing the number of the Arduino digital pin that supplies the Direction signal to the driver. The presence of an impulse - the motor rotates in one direction, the absence - in the other */
const int pinDir = 4;

//time delay between motor steps in ms
const int move_delay = 3;

//steps per full revolution
const int steps_rotate_360 = 200;


bool StepMode = (
{ 0, 0, 0},
{ 1, 0, 0},
{ 0, 1, 0},
{ 1, 1, 0},
{ 1, 1, 1} };

//array size StepMode
const int StepModeSize = 5;

/*Function in which all program variables are initialized*/
void setup()
{
/*set the Step and Direction contacts to output mode, that is, they output voltage*/
pinMode(pinStep, OUTPUT);
pinMode(pinDir, OUTPUT);

for(int i = 0; i< StepModePinsCount; i++)
{

}

//set the initial mode
digitalWrite(pinStep, HIGH);
digitalWrite(pinDir, LOW);
}

/*Loop function in which the behavior of the program is specified*/
void loop()
{
for(int i = 0; i< StepModeSize; i++)
{
for(int j = 0; j< StepModePinsCount; j++)
{
digitalWrite(StepModePins[j], StepMode[i][j] == 1 ? HIGH: LOW);
}

//rotate the motor one way, then the other
MakeRoundRotation();
}
}

/*function in which the motor takes 200 steps in one direction, then 200 in the opposite direction*/
void MakeRoundRotation()
{
//set the direction of rotation
digitalWrite(pinDir, HIGH);

for(int i = 0; i< steps_rotate_360; i++)
{
digitalWrite(pinStep, HIGH);
delay(move_delay);
digitalWrite(pinStep, LOW);
delay(move_delay);
}

delay(move_delay*10);

//set the direction of rotation to reverse
digitalWrite(pinDir, LOW);

for(int i = 0; i< steps_rotate_360; i++)
{
digitalWrite(pinStep, HIGH);
delay(move_delay);
digitalWrite(pinStep, LOW);
delay(move_delay);
}

delay(move_delay*10);
}

Well, the last thing we need to add to the circuit is external control. As in the previous article, we will add a button that sets the direction of rotation and a variable resistor (potentiometer), which will change the rotation speed. We will only have 5 speeds, in quantity possible modes step for the motor.

We supplement the diagram with new elements.

To connect the buttons we will use the following wires.

Program code.

/*Program for rotating a NEMA 17 stepper motor, 17HS4402 series + A4988 driver. The circuit includes a button with 3 positions (I, II, middle - off) and a potentiometer. The button adjusts the direction of rotation of the motor, and the data from the potentiometer shows which of the five motor step modes to turn on (full step, 1/2, 1/4, 1/8, 1/16 step)*/
/*integer constant storing the number of the Arduino digital pin that supplies the Step signal to the driver. Each impulse from this contact is a movement of the motor one step*/

const int pinStep = 5;

/*integer constant storing the number of the Arduino digital pin that supplies the Direction signal to the driver. The presence of an impulse - the motor rotates in one direction, the absence - in the other */
const int pinDir = 4;

/*Contacts from two positions of the button are digital*/
const int ButtonOn1 = 9;
const int ButtonOn2 = 10;

/*Contact registering the value of the potentiometer - analog*/
const int PotenciomData = 1;

//time delay between motor steps in ms
const int move_delay = 3;

/*integer constant indicating the time delay between reading the state of the button and the potentiometer*/
const int CheckButtonDelay = 15;

/*Integer variable indicating how much time has passed and whether it’s time to read the button state*/
int CurrentButtonDelay = 0;

/*contacts on the driver that set the motor step mode - MS1, MS2, MS3*/
int StepModePins = (8, 7, 6);

//size of the StepModePins array
const int StepModePinsCount = 3;

//button state is on/off
int ButtonState = 0;

//direction of rotation according to the button I - 1, II - 0
int ButtonDirection = 0;

/*Array storing the states of contacts MS1, MS2, MS3 of the driver, at which different modes rotation: full step, 1/2, 1/4, 1/8, 1/16th step*/
bool StepMode = (
{ 0, 0, 0},
{ 1, 0, 0},
{ 0, 1, 0},
{ 1, 1, 0},
{ 1, 1, 1} };

//array size StepMode
const int StepModeSize = 5;

//current array index StepMode
int StepModeIndex = 0;

/*Function in which all program variables are initialized*/
void setup()
{
/*set the Step and Direction contacts to output mode, that is, they output voltage*/
pinMode(pinStep, OUTPUT);
pinMode(pinDir, OUTPUT);

for(int i = 0; i< StepModePinsCount; i++)
{
pinMode(StepModePins[i], OUTPUT);
}

/*contacts from the button and potentiometer are set to input mode*/
pinMode(ButtonOn1, INPUT);
pinMode(ButtonOn2, INPUT);
pinMode(PotenciomData, INPUT);

//set the initial mode
digitalWrite(pinStep, LOW);
digitalWrite(pinDir, LOW);
}

/*Loop function in which the behavior of the program is specified*/
void loop()
{
if(CurrentButtonDelay >= CheckButtonDelay)
{
CheckButtonState();
CurrentButtonDelay = 0;
}

if(ButtonState == 1)
{
MakeMotorStep();
}

delay(move_delay);
CurrentButtonDelay += move_delay;
}

//function in which one motor step is performed
void MakeMotorStep()
{
digitalWrite(pinStep, HIGH);
digitalWrite(pinStep, LOW);
}

/*function in which the current state of the button and potentiometer is checked*/
void CheckButtonState()
{
int CurrentButtonState = 0, CurrentButtonDirection = 0, CurrentStepModeIndex = 0;

bool readbuttonparam = digitalRead(ButtonOn1);

if(readbuttonparam)
{
CurrentButtonState = 1;
CurrentButtonDirection = 1;
}

readbuttonparam = digitalRead(ButtonOn2);

if(readbuttonparam)
{
CurrentButtonState = 1;
CurrentButtonDirection = 0;
}

if(ButtonState != CurrentButtonState)
{
ButtonState = CurrentButtonState;
}

if(ButtonDirection != CurrentButtonDirection)
{
ButtonDirection = CurrentButtonDirection;
digitalWrite(pinDir, ButtonDirection);
}

CurrentStepModeIndex = map(analogRead(PotenciomData), 0, 1023, 0, StepModeSize-1);
if(StepModeIndex != CurrentStepModeIndex)
{
StepModeIndex = CurrentStepModeIndex;
for(int i = 0; i< StepModePinsCount; i++)
{
digitalWrite(StepModePins[i], StepMode[i]);
}
}
}

Now a more interesting task has appeared. Control Nema 17 stepper motor (datasheet). This model from original manufacturer sells for about $40. Chinese copies They cost one and a half to two times cheaper - about 20-30 dollars. Very successful model, which is often used in 3D printers and CNC projects. The first problem that arose was how to choose a driver for this engine. The current on the Arduino pins is not enough to power it.

Selecting a driver to control Nema 17

Google suggested that to revive Nema 17 you can use the A4988 driver from Poulou (datasheet).

In addition, there is the option of using L293D chips. But A4988 is considered more suitable option, so we stopped there to avoid potential problems.

Nema 17 connection via A4988

The connection was implemented based on this topic on the Arduino forum. The picture is shown below.


Actually, this scheme is present on almost every blog site dedicated to Arduino. The board was powered from a 12 volt power source. But the engine did not rotate. We checked all connections, checked again and again...

First problem

Our 12 volt adapter did not produce enough current. As a result, the adapter was replaced with 8 AA batteries. And the engine began to rotate! Well, then I wanted to jump from the breadboard to direct connection. And then it arose

Second problem

When everything was unsoldered, the engine stopped moving again. Why? It's still not clear. I had to go back to the breadboard. And here the second problem arose. It was worthwhile to first sit on the forums or carefully read the datasheet. You cannot connect or disconnect the motor when power is supplied to the controller! As a result, the A4988 controller burned out safely.

This problem was resolved by purchasing a new driver on eBay. Now, taking into account the accumulated sad experience, Nema 17 was connected to the A4988 and launched, but...

Stepper motor vibrates a lot

While the rotor was rotating, the engine vibrated strongly. There was no talk of smooth movement. Google to the rescue again. The first thought is that the windings are connected incorrectly. Familiarization with the datasheet of the stepper motor and several forums convinced me that this was not the problem. At incorrect connection windings, the motor simply will not work. The solution to the problem lay in the sketch.

Program for Arduino

It turned out that there is a wonderful library for stepper motors, written by the guys from Adafruit. We use the AcclStepper library and stepper motor starts working smoothly, without excessive vibrations.

Main conclusions

  1. Never connect/disconnect the motor while the controller is powered.
  2. When choosing a power source, pay attention not only to the voltage, but also to the power of the adapter.
  3. Don't be upset if the A4988 controller fails. Just order a new one ;)
  4. Use the AcclStepper library instead of bare Arduino code. A stepper motor using this library will operate without unnecessary vibrations.

Sketches for controlling a stepper motor

Simple Arduino code to test a stepper motor

//easy connection A4988

//reset and sleep pins are connected together

//connect VDD to 3.3V or 5V pin on Arduino

//connect GND to Arduino GND (GND next to VDD)

//connect 1A and 1B to 1 coil of stepper motor

//connect 2A and 2B to stepper motor coil 2

//connect VMOT to power supply (9V power supply + term)

//connect GRD to power source (9V power supply - term)

int stp = 13; //connect pin 13 to step

int dir = 12; //connect 12 pins to dir

pinMode(stp, OUTPUT);

pinMode(dir, OUTPUT);

if (a< 200) // вращение на 200 шагов в направлении 1

digitalWrite(stp, HIGH);

digitalWrite(stp, LOW);

else ( digitalWrite(dir, HIGH);

digitalWrite(stp, HIGH);

digitalWrite(stp, LOW);

if (a>400) // rotate 200 steps in direction 2

digitalWrite(dir, LOW);

The second code is for Arduino to make the motor rotate smoothly. The AccelStepper library is used.

#include

AccelStepper Stepper1(1,13,12); //uses pins 12 and 13 for dir and step, 1 - "external driver" mode (A4988)

int dir = 1; //used to change direction

Stepper1.setMaxSpeed(3000); //set the maximum rotation speed of the motor rotor (steps/second)

Stepper1.setAcceleration(13000); //set acceleration (steps/second^2)

if(Stepper1.distanceToGo()==0)( //check whether the motor has completed the previous movement

Stepper1.move(1600*dir); //sets the next move to 1600 steps (if dir is -1 it will move -1600 -> opposite direction)

dir = dir*(-1); //negative value of dir, due to which rotation in the opposite direction is implemented

delay(1000); //delay for 1 second

Stepper1.run(); //start the stepper motor. This line is repeated over and over again to keep the motor spinning continuously.

Here we will learn how to write a basic program that can do something interesting for a beginner. Here you will learn how to write a simple sketch for Arduino using a standard IDE. We'll skip the use of I/O for now, but focus on USB communications. The syntax of the Arduino language exactly repeats the C language, so we will not dwell on it. We will focus on specific aspects of the Arduino language, in which you can use all the principles that are inherent in the C language: variables, operators, states, types, constants, etc.

The use of stepper motors is one of the simplest, cheapest and easiest solutions for implementing precision positioning systems. These motors are very commonly used in various CNC machines and robots. Today I will talk about how stepper motors are designed and how they work.

The KY-040 rotation encoder is a rotary sensor that indicates the degree of rotation of the axis and in which direction it rotates.

This is an excellent device for monitoring stepper and servo motors. It will make a cool control for the controller settings menu. You can also use it as a digital potentiometer.

Required hardware - Arduino and USB cable

This tutorial assumes you are using an Arduino Uno, Arduino Duemilanove, Nano or Diecimila.

You will also need a USB cable (with USB-A and USB-B connectors): such as, for example, to connect a USB printer. (For Arduino Nano you will need an A to mini-B cable instead).

Also now boards with micro USB have become popular - for example, from Chinese manufacturers Robotdyn. They appeal to me more from the outside

universality, but as the oldfags say - the more metal in the connector, the more reliable it is!

1. Control small motors

Controlling a small engine can be quite simple. If the motor is small enough, it can be directly connected to the Arduino pin, and simply changing the level of the control signal from logic one to zero will control the motor. This project will teach you the basic logic behind controlling an electric motor; however, this is not the standard way to connect motors to Arduino. We recommend that you study this method, and then move on to the next step - control motors using transistors.

Let's connect a miniature vibration motor to our Arduino.

Servo motor MG995 and Arduino

The MG995 servo motor comes with a 30cm long wire and 3 ‘S’ female pins. The servo output shaft rotates approximately 120 degrees (60 degrees in each direction). To control the MG995 servos, you can use any controllers with 5 V logic power, including Arduino.

The servo is manufactured in a plastic case. At the output there is a gearbox with metal gears. The kit includes plastic rockers of various form factors.

Connect the motor, power supply and relay

Connection diagram:

Positive motor contact - switch 1 COM input to relay

Negative motor contact - switch 2 COM input to relay

Our company has started shipping the DM805-AI driver.

The main highlight of the driver is the ability to control the rotation of a stepper motor without an external pulse device. This is ensured by a built-in pulse generator, the frequency of which is determined by the voltage supplied to the 0 - 5V input of the driver. Moreover, this voltage can be taken either from an external source (for example, a voltage output signal from a controller) or from the driver itself. The presence of an internal 5V voltage source allows the use of an external potentiometer.

The DM805-AI driver is suitable for applications where you need to set the motor rotation speed using a potentiometer or analog signal 0 - 5V, and in which they were usually used brushless motors with gearbox. This driver allows you to use stepper motors without a gearbox for such tasks, since the stepper motor provides high torque from minimal speeds and is also quiet at low speeds.

Peculiarities:

  • self-diagnosis and automatic installation operating current of windings;
  • microstepping up to 12800 pulses/revolution;
  • electrical diagram provides protection against mid-frequency resonance;
  • internal source 5VDC;
  • built-in potentiometers;
  • two preset speeds;
  • preset tasks for acceleration and braking;
  • adjusting the speed of rotation of the motor shaft with a signal 0 - 5V;
  • winding current from 0.3 to 5A;
  • protection against overvoltage and current.

The driver can be used in four modes:

  1. Pulse is the classic STEP/DIR.
  2. Speed ​​setting using a 0 - 5V signal.
  3. Setting the speed using a potentiometer.
  4. Rotation at any of two preset speeds.

An example of using the speed setting mode from an external 5V source.

If the task at hand does not require precise discrete positioning, but rather, for example, the movement of one limit switch to another is sufficient, then in this case there is no need to use pulse control of the driver, but you can get by with a simpler voltage regulator. Pulse control requires an output module that supports high-frequency discrete output (in the case of using a PLC, an input-output module that supports high-frequency mode costs much more than standard modules), and it is also necessary to correctly write mathematics, taking into account such issues as accelerating and braking characteristics. When using voltage speed setting, there is no need for complex algorithms: the braking and accelerating characteristics, as well as the speed limit, are set using regulators on the driver itself, and all that is required from the control system is to provide a signal in the range from 0 to 5V. Corresponding analog output modules are generally inexpensive. The direction of rotation is also determined by the applied voltage: if the voltage is between 0 and 2.5V - rotation in one direction, from 2.5 to 5V - in the other.

An example of using the control mode from an external potentiometer.

A four-position joystick potentiometer that sets deviations along the X and Y axes. Two DM805-AI drivers are connected to the joystick, providing operation on the corresponding axes. The direction of joystick deflection sets the axis and direction, the amplitude of deflection sets the rotation speed.

An example of using preset speeds.

In this mode of using the driver, two operating speeds are set using potentiometers located on it. In the future, the selection of speeds and direction of rotation is made using simple “dry contacts”.

This mode allows you to further simplify speed control, compared even with 0 - 5V voltage control. For example, you can automatically switch speed from high to low using the controller's relay output when an event occurs.

About control in pulse mode, read our article “Control of a stepper motor.”

The ability to automatically configure for a specific stepper motor is very convenient, or useful especially when you don’t have a passport for the motor at hand, and you don’t remember its operating current (and this most often happens). However, if you want to tinker with the settings yourself, then an RS232 serial port and the necessary software for a personal computer.

In conclusion, the DM805-AI driver will allow you to try and choose the type of stepper motor control that is convenient for you.