Having a look around on the internet, there are a few forums in which stepper motor control is discussed, however, none of them go into the detail required for an electronics newbie to be able to get their motor up and running with the hardware connections and the sketch. So here’s our complete step by step guide to get any Arduino to control a stepper motor.
The Pololu Simple High-Power Motor Controller 18v15 makes basic control of brushed DC motors easy, with the free Simple Motor Control Center software enabling quick configuration over USB. The controller supports four interface modes: USB, TTL serial, analog voltage, and hobby radio control (RC). The download version of Pololu Simple Motor Controller is 1.2.0. Pololu Simple Motor Controller is distributed free of charge. The contents of the download are original and were not modified in any way.
Being able to control a stepper motor with your Arduino opens up a world of opportunity for new projects. Stepper motors offer precise control over their speed, position and direction so they are a popular choice for robotics, 3D printers, CNC projects and servo drive mechanisms.
We will be using the Pololu range of stepper motor drivers as they are really cheap, easy to work with, offer simplistic control and are compatible with all of the Arduino development boards.
What You Will Need To Control A Stepper Motor With Your Arduino
- Arduino (Uno Used Here) – Buy Here
- Power Supply (12V – 30W / 2.5A) – Buy Here
- Pololu Stepper Motor Driver
- A4988 – Buy 1A Driver
- DRV8825 – Buy 2A Driver
- Stepper Motor (1A or 2A To Match Driver) – Buy Here 1A, Buy Here 2A
- 100µF 12V Capacitor – Buy Here
How To Control Your Stepper Motor
First we will start by connecting the hardware together and then we will move on to the software/sketch. In this example we have used the same power supply to power the Arduino and the motor through the Pololu driver however these can be two separate power supplies.
Assemble The Components
You have two options when assembling the components, the first is to solder all of the connections to the Pololu motor controller and then solder the connections to the Arduino through a pin header and the second option is to solder pin headers onto the underside of the Pololu motor controller and then plug it into a breadboard to use jumpers to connect it to the Arduino. Use the soldered connections for a permanent installation or on something which is going to be moving around a lot and use the breadboard if you are just playing around with ideas on a bench.
The basic circuit and connections to the Arduino and the Pololu driver are shown below, click to enlarge the image if required:
Connect the Pololu direction pin to Arduino pin 0 and the step pin to Arduino pin 1 as these are setup in the sketch. You can connect more than one motor to the Arduino by making simultaneous connections to any of the available pins.
Bridge the reset and sleep pins on the drive controller as we will not be using these.
Your stepper motor should have four different coloured wires, these will be identified on your motors data sheet as shown below:
The wires work as pairs, one on each side of the opposing motor windings, in this case red and yellow form one pair and blue and orange form a second pair. These wires need to be connected in their pairs to the 1A and 1B and the 2A and 2B pins on the drive controller. It doesn’t matter which way around they are connected as long as one pair is connected to the 1 pins and the other pair to the 2 pins. Your motor may have different coloured wires so it is important to get the datasheet, alternately you can measure the resistance across wires with a multimeter, the pairs will have a resistance and the non pairs will show open circuit.
Setting The Driver Current Limit
Before running your motor, your need to set the current limit on your stepper motor driver, this is done by adjusting the small potentiometer on the driver. To do this, you’ll need to find your motors rated current per phase, which should be on the data sheet or in the product description. You’ll then need to set the driver’s maximum output current to be less than the motor rated current to avoid burning the motor out.
Next you’ll need to find your motor driver’s Vref equation, this is also available on the datasheet or in the product description. You need to input your motors rated current into the Vref equation to get your required Vref voltage.
Now power up your Arduino and motor driver and measure the actual Vref, this is typically done between GND and the Vref measurement point denoted as a white dot on the board or alternatively between GND and the metal top of the potentiometer. Adjust the potentiometer until the actual Vref matches the required Vref you have calculated.
You can also calculate your Vref using a slightly lower current to avoid over stressing the motor and producing excess heat.
Choosing Different Components
Choosing A Different Stepper Motor
Depending on your application, you may require a bigger or smaller stepper motor. Stepper motors are generally sized by their output torque, you will need to figure our, either through experimentation or through calculations how much torque you require. You can then select a motor which can produce your required torque, the data sheet will then tell you the required current and then you can select a motor controller to suite.
Sizing the Stepper Motor Driver
The drive controller used in this example, the A4988 can drive a motor up to 1A and the second controller mentioned in the parts list, the DRV8825 can drive a motor up to 2A. Pololu make a number of stepper motor drive controllers (shown here) for different size motors, it is just important that you have a controller which can produce more current than the motor requires otherwise it will burn out.
Upload The Sketch
Now you can upload your sketch onto your Arduino, if you haven’t uploaded a sketch before then follow this guide on getting started.