Introduction: Stepper Motor: Starting at Low Cost - Pt1

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects.

In this first video of a four-episode series, I introduce several fundamental concepts about the stepper motor, and then we practice using an engine taken from an "old" scanner and an Arduino. This allows for a low cost experiment.

As one of its main benefits, I explain in the video how the pitch motor allows for more precise control of speed and positioning. However, it needs a more complex control for operation. Its strong point is precision, not speed or torque, unlike other types of engines.

Step 1: Key Features

• There are no brushes or switches to increase service life.

• They allow for more precise control of speed and positioning.

• They require more complex control for operation.

• Rotation needs to be performed at discrete and sequential angles (called steps).

• The strong point is precision, not speed or torque, unlike other types of engines.

Step 2: Assembly

In our assembly, we use a motor that I removed from a scanner, which is basically equivalent to a Nema 17. We have a driver, a voltage regulator, and an Arduino Uno. I also really like the stepper engine, because I consider it indestructible.

Step 3: Extracting the Scanner Engine

The scanner where I got the engine from worked continuously for about five years, but suddenly went kaput. Though the engine was perfect, unlike the gears. Thus, I say that the stepper motor is an "engineering marvel.”

Check some images of the disassembly.


Remember to be careful not to cut the wires.

Step 4: Scanner Engine

Step 5: Coil Configuration (Types)

The internal coils of a step motor can appear in two basic configurations: UNIPOLAR and BIPOLAR. The way the coils are connected will determine the form of motor control, and the type of driver that can be used.

Step 6: Bipolar Motor

The internal coils of a BIPOLAR pitch motor are independent (A + A- and B + B-). They usually have 4 wires.

To identify the pairs (A + A- or B + B-), we can use an ohmmeter. The electrical resistance presented by the coils is low (on the order of a few ohms).

If we measure some resistance value, we have a pair.

The identification of which coil is A or B is not important in this case. When mounting the activation circuit, we will notice if any of the coils were inverted (+ and -), because the motor instead of turning will oscillate from side to side. Simply reverse the wires of any of the coils.

Bipolar motors need a driver capable of reversing the polarity of the voltage applied to the coils (usually an H-bridge).

Step 7: Digital Electronics and Step Motors

To control the pitch motors, we use digital circuits to determine the trigger sequence of the coils. And from that, determine your speed of rotation, direction, and positioning.

For this, we will program an Arduino UNO to set the drive in the sequence and speed that we want.

For BIPOLAR engines in FULL STEP mode:

In FULL STEP mode, the coils are activated and have their polarizations inverted sequentially.

Step 8: Knowing About the Engine...

With the model number of the engine, we look for its respective datasheet.

We found a subsequent series. In it, we could use a table of lengths to find the nearest engine.

As the engine is 30mm long, the nearest series is 17PM - K2.

We need to get more information from our engine to be able to characterize it. One important measure that can help is the strength of the coils and number of wires.

- Our engine has 4 wires.

- Measuring the winding resistance, we find approximately 2.7 ohms.

Of the two engines of the 17PM - K2 series, one of them has a similar resistance, O 17PM - K249U. This may be the most current replacement for our engine.

ATTENTION!!!

OUR INVESTIGATION HAS GIVEN US AN ENGINE SIMILAR TO OUR ENGINE, BUT THIS DOESN’T MEAN IT IS THE SAME ENGINE. IT WILL SERVE AS OUR STARTING POINT, AND WE’LL USE IT AS A GUIDE. BUT WE SHOULD NEVER JUDGE THAT THE INFORMATION IS ALWAYS COMPLETELY RELATIVE TO OUR ENGINE.

THE MOST SUITABLE OPTION IS ALWAYS TO HAVE THE DATA SHEET THAT REALLY CORRESPONDS TO THE COMPONENT.

Step 9: Engine Datasheet...

Using the datasheet of our engine, we find the following information:

- Number of steps per revolution: 200 (1.8 degrees per step)

- Operating current: possibly 800mA

- Supply voltage: possibly up to 24V

- Coil configuration: bipolar (4 wires)

This information will be used for preliminary guidance only.

Step 10: Choosing the Driver for Control

We can’t use the Arduino to directly control the motor coils.

For this, it is necessary to use an intermediate circuit capable for supplying the appropriate voltages and currents. In this case, this is a circuit called a driver.

Its function will be to adjust the control signals sent by the Arduino to the appropriate levels.

For our type of motor, we will use the L298N, which has 2 H-bridges internally where we will connect each coil. This will be responsible for the correct polarization and the current supply.

The L298N can supply 2 amps per channel. Our expectation is that the engine has consumption that’s around 800mA. As we will use an adjustable voltage source to power the motor and monitor the drained current from the source, we can safely carry out the assembly.

We will do this by increasing the supply voltage and monitoring the current until the motor has the proper torque.

Step 11: Description of Pins

Step 12: ​Activation Sequence

Step 13: Mounting the Circuit

Step 14: Arduino Source Code

Global Declarations:

We start by defining constants that will represent Arduino pins D2, D3, D4, D4, and D5. These pins will be responsible for transmitting the drive sequence to the driver.

We also create a variable called "speed,” which we can use to change the motor speed. We create it as a variable for possible exploration related to the speed of the engine that uses the code.

// Declaração Global de constantes que representarão os pinos do Arduino
const byte INPUT_1 = 2; const byte INPUT_2 = 3; const byte INPUT_3 = 4; const byte INPUT_4 = 5; //criando uma variável que determinará a velocidade do motor int velocidade = 1000;

Setup - Setting the Arduino

In the void setup () function, we set the function of the control pins as digital outputs.

void setup() {
// Ajustando os pinos do Arduino para operarem como saídas digitais pinMode(INPUT_1, OUTPUT); pinMode(INPUT_2, OUTPUT); pinMode(INPUT_3, OUTPUT); pinMode(INPUT_4, OUTPUT); }

Loop - Running the Activation Sequence

It will be in the void loop () function where we will execute the sequential activation of the command ports, which will transmit this sequence to the driver L298N that will consequently activate the coils.

The code simply activates the pins as shown in the table for each of the steps.

Let's see in detail.

void loop() {
// Passo 1: + - - - digitalWrite(INPUT_1, HIGH); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade); // Passo 2: - + - - digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, HIGH); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade); // Passo 3: - - + - digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, HIGH); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade); // Passo 4: - - - + digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, HIGH); //Aguarda delay(velocidade); }

Loop Detail - Step 1

// Passo 1: + - - -
digitalWrite(INPUT_1, HIGH); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade);

Loop Detail - Step 2

// Passo 2: - + - -
digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, HIGH); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade);

Loop Detail - Step 3

// Passo 3: - - + -
digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, HIGH); digitalWrite(INPUT_4, LOW); //Aguarda delay(velocidade);

Loop Detail - Step 4

// Passo 4: - - - +
digitalWrite(INPUT_1, LOW); digitalWrite(INPUT_2, LOW); digitalWrite(INPUT_3, LOW); digitalWrite(INPUT_4, HIGH); //Aguarda delay(velocidade);

Step 15: Understanding the Program

Step 16: General Scheme: