Arduino - Stepper Motor
This tutorial is currently updating.
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
|1||×||Arduino Motor Shield R3|
About Stepper Motor
There are two types of step motors: bipolar stepper motor and unipolar stepper motor. They differ from each other in the internal structure and the working principle.
With the naked eyes, they look similar to each other. However, we can distinguish them by the number of wires. The bipolar motor usually has four wires. The unipolar motor usually has six wires.
Controlling the bipolar stepper motor and the unipolar stepper motor is different. Fortunately, we can control the unipolar stepper as if it is a bipolar stepper motor by using four of six wires.
How To Control Stepper Motor with Arduino
The stepper motor requires more power than Arduino board can give it, so you’ll need another power supply for it. Ideally, Stepper motor's datasheet or manual lets you know the voltage of the power supply.
We CANNOT connect the stepper motor directly to Arduino. We MUST connect via a motor driver or motor controller.
The motor driver and motor controller can be:
- Chip (e.g. SN754410)
- Module (e.g. A4988)
- Shield (e.g. Arduino Motor Shield Rev3, Stepper Motor Controller PES-2605, Adafruit Motor/Stepper/Servo Shield)
To make it easy for beginners, we recommend using one of the following shields:
- Arduino Motor Shield Rev3: this is an official shield from Arduino.
- Stepper Motor Controller PES-2605: this is very easy to use. Besides, its library supports various functions. It supports the micro-stepping method that makes the stepper motor move smoothly. The company that makes this shield has been good at providing documentation and tutorials. However, to use this shield, we need to use it along with the PHPoC WiFi shield. This does NOT add any difficulty but adds more cost.
If the cost is no matter for you, we recommend using the Stepper Motor Controller PES-2605.
If you need to save costs, we recommend using Arduino Motor Shield Rev3.
Using Arduino Motor Shield Rev3
- Stack Arduino Motor Shield Rev3 on Arduino Uno
- Connect stepper motor to Arduino Motor Shield Rev3
Image is developed using Fritzing
- Download or copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Open Serial Monitor to see result:
1. Stepper motor vibrates while moving
Do NOT worry if the stepper motor vibrates while moving. This is a characteristic of the stepper motor. We can reduce vibration by using the micro-stepping control method.
Also, because of this characteristic, if we control properly, the stepper motor can produce musical sounds as if it is a musical instrument. You can see this project on Arduino Project Hub .
2. Method of controlling stepper motors
- Full-step: The unit of moving is one step, which is equivalent a value of degree specified in stepper motor's datasheet or manual.
- Half-step: divides each full step into two smaller steps. The unit of moving is half of the full step. This method allows the motor move with double resolution.
- Micro-step: divides each full step into many smaller steps. The unit of moving is a fraction of the full step. The fraction can be 1/4, 1/8, 1/16, 1/32 or even more. This method allows the motor move with higher resolution. It also make motor move smoother at low speeds. The bigger dividend is, the higher resolution and the smoother motion is.
For example, If the motor's datasheet specifies 1.8 degree/step:
- Full-step: The motor can move with 1.8 degree/step <⇒ 200 steps/ revolution
- Half-step: The motor can move with 0.9 degree/step <⇒ 400 steps/ revolution
- Micro-step: The motor can move with 0.45, 0.225, 1125, 0.05625 degree/step <⇒ 800, 1600, 3200, 6400... steps/ revolution
The above code used the full-step control method.
3. Resonance Issue
This is the advanced usages. The beginners do NOT need to pay attention to it. This happens in a speed range, in which the step rate equals the motor’s natural frequency. There may be an audible change in noise made by the motor, as well as an increase in vibration. In real applications, the developer SHOULD pay attention to this issue.