How to control a Stepper Motor using the Easy Driver and an Arduino
There are many ways to control stepper motors using an Arduino.
In this tutorial we will see how to control a Nema 17 size stepper motor using an Analog Joystick.
To connect the stepper to the UNO we will be using the popular and inexpensive Easy Driver controller board.
The motor we are using has 1.8 degrees per steps, so a full revolution is equal to 200 full steps (360 degrees / 1.8), and is rated at 0.4 Amp at 12V.
The Easy Driver can drive up to about 750mA per phase, so it’s perfect to be used with this motor. It defaults to 1/8 step mode (So if your motor has 200 full steps per revolution, you would get 1600 steps/rev using this 1/8 step mode).
For our tutorial we will override this setting by setting MS1 and MS2 pin on the Easy Driver to default to full step mode. You can see which settings are available in the Arduino sketch below.
As you can see the connections are pretty straightforward:
Pin 3 is connected to Steps pin on Easy Driver
Pin 2 is connected to Direction pin
Pin 5 is connected to MS1 pin
Pin 4 is connected to MS2 pin
Pin 7 is connected to SLEEP pin
Pin A0 connected to joystick X-axis
The Ground and Voltage pins of the Easy Driver are connected to a 1 Amp 12V power supply.
Of course we could have added some Limit Switches to make sure our stepper motor does not rotate too far.
But for our tutorial we will assume that we position the belt clip in the middle position.
To visualize better how the motor is being controlled, we will not be using any Libraries in our code.
Instead we will be turning On and Off the Step pin of the Easy Driver and put a delay() in between to control the speed.
Since we are not using limit switches, the code will assume that we already positioned the belt clip in the middle position before turning on the power.
We calculated that it takes approx. 10.25 full revolutions of the stepper motor to cover the distance between the motor and the idler pulley. If our motor in full step mode takes 200 steps to make 1 revolution, then it will take 2050 steps to cover the distance.
So the code will assume that the belt clip is positioned in the middle at startup, or 1025 steps.
As always, please check out the tutorial video to have more information.
Copy and paste the above code in the Arduino IDE to program your Arduino.