In this example we'll wire up and use a bi-polar stepper motor with recommended 12V motor voltage, and 200 steps per rotation.
Wiring
We'll wire it to a Metro, but you can use any microcontroller you like!
Connect:
- Vmotor to 12V (red wire)
- Vcc to 5V (orange wire)
- GND to ground
- AIN2 to Digital 4
- AIN1 to Digital 5
- BIN1 to Digital 6
- BIN2 to Digital 7
- PWMA and PWMB to Vcc (orange wire)
Then hook one stepper motor coil to Motor A (red and yellow) and the second coil to Motor B (green and gray/brown). If you have another motor, you'll need to experiment a little to figure out which wires are which coil. Check any documentation you have! You can use a multimeter to measure between wires, the ones with a small resistance between them are a pair to a coil, for example. If the motor is vibrating but not spinning, check all wires are connected and try flipping around a pair or rechecking the wire pairs.
If you have a unipolar motor, there will be a 5th or 6th wire that is the 'common' wire. Connect these wires to the GND pins in between the Motor A and B outputs on the breakout.
Software
We'll use the built-in Arduino Stepper library, but you can manually toggle the AIN1/AIN2/BIN1/BIN2 pins with your own favorite microcontroller setup
#include <Stepper.h> // change this to the number of steps on your motor #define STEPS 200 // create an instance of the stepper class, specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS, 4, 5, 6, 7); void setup() { Serial.begin(9600); Serial.println("Stepper test!"); // set the speed of the motor to 30 RPMs stepper.setSpeed(60); } void loop() { Serial.println("Forward"); stepper.step(STEPS); Serial.println("Backward"); stepper.step(-STEPS); }
Basically after you make the Stepper object with the 4 control pins, you can set the rotational speed (in RPM) with setSpeed(rpm) and then step forward or backwards with .step(steps) where steps is positive for 'forward' and negative for 'backward'
Page last edited March 08, 2024
Text editor powered by tinymce.