In this tutorial, you will learn to configure the stepper motors with the Arduino Uno.
Contents:
1. Introduction
In an earlier tutorial, we discussed how to use the servo motors. Stepper motors are generally more accurate and can bear greater amount of torque. Here, we will be using the stepper motor from a scrap DVD/CD drive and will configure it with our controller. You can use any stepper motor with four wires for this project.
2. Materials Required
- A Stepper Motor (NEMA-17)
- Arduino Nano/Uno
- Jumper wires
- 12V-2A adapter
- 100uF capacitor
- A4988 module
- Multimeter
3. Hardware Explanation
The stepper motor is a powerful motor so we need an external supply for the same. The main work is done by the A4988 motor driver . The 100uF capacitor acts as a decoupling capacitor and reduces the sound generated in the circuit. I am using the stepper motor of the scrap DVD drive. You can choose any. First of all, see the four wires shown below.
In this, two wires are of the same phase while two are of others. To check this, select the Shorting method of the multimeter and keep it at the two wires. The set of wires for which it beeps are in the same phase. Mark them or remember them.
4. The Circuit
Carefully observe the pinout of the A4988 motor driver. Connect the Vcc and GND pin and then connect the DIR pin to D2 and the step pin to D3. Connect the capacitor between Vmot and the GND and then connect it with the power supply at the end. The wires of the same phase will be connected to 1A and 1B and the other two wires of the same phase to 2A and 2B. Now get ready to upload the code.
5. Arduino Code
Upload this code to the board without connecting the setup to the adaptor. Connect it after uploading the code. You will see your stepper motor running.
const int dirPin =2;
const int stepPin=3;
const int stepsPerRev=200;
void setup() {
// put your setup code here, to run once:
pinMode(dirPin,OUTPUT);
pinMode(stepPin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(dirPin,HIGH);
for(int x=0;x<stepsPerRev;x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(250);
digitalWrite(dirPin,LOW);
for(int x=0;(x<stepsPerRev);x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(250);
}
6 . DIY Project’s Idea
You can make many DIY projects with the stepper motor of the DVD drives. One main project is the CNC plotter. It is a 2.5 axis based plotter that plots the sketch of the image passed by the computer. An extra servo motor is required for the z-axis. While the x and y-axis are the stepper motors. I hope you will try this amazing project on your own.
I hope you were able to run the stepper motor. Feel free to write in the comment section. Happy Learning!