In: Physics
A4988 drive can be used. We can control stepper motor with 2 pins one step and other direction.
Connection :
1. Connect driver pinVDD and gnd to Arduino pins VDD and gnd to provide supply (3-5.5V)
2. 1A and 1B connect to motor coil and 2A and 2B to other motor coil.
3. To power motor connect GND and VMOT to motor power supply connection. Use a decoupling 47picofarad capacitor between VMOT and GND in parallel to power supply of the motor
4. Connect STEP of driver to pin 3 of Arduino
5. Connect DIR of driver to pin 4 of Arduino
6. Connect reset pin to SLEEP pin in order to bring it high and enable board . Logic low in SLEEP puts board in sleep minimizes power consumption.
Our motor now will operate in full stepsize (1.8 degrees per step)
Note : Use pins MS1 MS2 and MS3 of the driver board to operate motor in different stepsizes. Logic high at ENA pin keep the outputs disabled.
Arduino code
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a
particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}
***************************************************
In the code first we set direction pin high to enable movement in one direction. Our motor makes on rotation in steps of 1.8 degrees. After one rotation of 200 steps a delay of 1 second will be there then direction of rotation will change. Then motor will take 400 steps and complete two rotations in opposite direction .