Stepper motor control with Arduino.

Stepper motor control with Arduino.

Hello friends, Welcome back to my blog. Today we are going to talk about a motor control topic. In a previous post, we explained how to control a servo motor. Read it using this link Servo motor. So, let’s look at the topic today.

What is a stepper motor?

When we take a typical DC motor, we can get two functions out of it. These include changing the direction of rotation by changing the anode and cathode and changing the supply potential to control the speed of the motor. However, these motors cannot control the steps and volume of rotation. For that, we can use stepper motors. With these stepper motors, we can control the turning steps. See the picture below.

It has two coils. We can rotate this motor according to the pattern that supplies power to these coils. We can see a large number of stepper motors and the two main types are depending on the way the coils are wrapped.

Bipolar

Stepper motor control with Arduino.

Unipolar

Stepper motor control with Arduino.

There are different types of motors depending on how the wires are connected to them. The bipolar types of motors have four wires. Other stepper motors have wires 4,5,6 etc. This type of motor cannot be controlled by supplying power in the normal way. This requires a special circuit. That is, an H-bridge circuit must be used. This circuit has four transistors. I described the H-Bridge circuit in a previous post. Click this link and read it Click me. There are two main types of ICs that contain these h-bridges. Those are l298N and l293D. We can make a stepper driver circuit using these ICs.But it is very heavy work. We will use a stepper driver board to carry out this project.

Today stepper motor we use consists of five wires. It can be controlled via a stepper-driver board. This can be controlled by four digital pins on the Arduino board. These four pins must be connected to the IN1, IN2, IN3, and IN4 pins on the drive board. This board should be connected to a 5 to 12 v supply.

Ok, let’s do this project practically. The required components are as follows.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Identify the components.

Step 2

Connect these components using the circuit diagram below.

Step 3

Let’s look at the code below.

  • The complete program of this project – Download
/*Stepper motor control.
 *created by the SriTu Tech team.
 *Read the code below and use it for any of your creations
 */

#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
void setup() {
  stepper.setSpeed(200);//set motor speed
}
void loop() {
  stepper.step(200);
  delay(1000);//delay
  stepper.step(200);
}

For this code, you need to add a stepper library file. Put it into the Arduino IDE using the steps below.

#include <Stepper.h>

This code specifies the number of steps required to rotate the motor.

#define STEPS 100

This code includes the digital PINs used and the number of steps.

Stepper stepper(STEPS, 8, 9, 10, 11);

The code in the void setup controls the speed of the motor.

void setup() {
  stepper.setSpeed(200);//set motor speed
}

This code causes the motor to rotate. Change its values ​​and try again.

void loop() {
  stepper.step(200);
  delay(1000);//delay
  stepper.step(200);
}

Step 4

Select the board and port. After, click the upload button.

Now, you can test this project. The full video guide is below. We will meet in the next post. Have a good day.

Stepper motor control with Arduino.

Similar Posts

Leave a Reply

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