Let’s control a Step Motor with a custom-designed shield. It’s just like the Motor Driver Shield, but cheaper and more fun because we make it ourselves.
Driver Shield Parts
Total BOM cost for this shield is $8.63, plus $8.40 for the board, totals $17.04.
|1||Mouser||511-L298||Motor / Motion / Ignition Controllers & Drivers Dual Full Bridge||$4.67||Datasheet|
|8||Mouser||821-1N4001||Rectifiers Vr/50V Io/1A T/R||$0.16||Datasheet|
|3||Mouser||651-1935161||Fixed Terminal Blocks PT 1.5/2-5.0-H||$0.34||Datasheet|
|2||Mouser||647-UVR1E101MED1TA||Aluminum Electrolytic Capacitors – Leaded 25volts 100uF||$0.04||Datasheet|
|2||Mosuer||660-MF1/4DC1002F||Metal Film Resistors 10K 1% 100PPM||$0.04||Datasheet|
|1||Sparkfun||PRT-10007||Arduino Stackable Header Kit||$1.50|
The L298 Motor Driver is the chip at the heart of this all. This is the one that handles all the current, allowing us to make small signal inputs with our Arduino to control motors of large voltages. This part is also available from Sparkfun for ~$1.50 less, so if BOM cost is important, you can get it there.
Diodes are needed to protect against reverse pulses coming from the motors back onto the rest of the circuit and ruining things.
Screw terminals for attaching the step motor wires and external power.
Capacitors are needed to even out the flow of power.
The board has a pair of switches separate from the motor circuit for me to give inputs into the Arduino that the sketch can use for whatever it wants. These resistors are there to pull down the switches to ground. It turns out that using these is a bad idea. Instead, I should have used the Arduino’s internal pull-up resistors and then connected the switches. In a future revision, I will change that and remove these resistors.
The trick to making a shield is getting these great stackable headers which stick through the board into the Arduino, and let you attach something into them above.
|1||Sparkfun||ROB-09238||Stepper Motor with Cable||$14.95|
|1||Sparkfun||BOB-09540||Breakout Board for L298N Full-Bridge Motor Driver||$2.95|
The Sparkfun motor is a great motor to start out with. Sturdy, powerful, priced right. That said, this setup will work with any bipolar step motor.
When working with this on a breadboard, having the little breakout board for the L298 is critical. We won’t need it when the shield is done, though.
First, it’s good to be familiar with this stuff:
- Stepper motor info. Basic explanation of what a step motor is, why it’s different, and how it operates.
- L298 Stepper Motor Control A tutorial on using the L298 to control a stepper with a PIC microcontroller.
- Arduino Stepper Library. Arduino comes with a stock library which is adequate for controlling steppers right out of the box.
- Beginners Guide to Arduino Shield PCB. Guidance on how to create an Arduino Shield from scratch.
Fundamentally, we are building the “Reference Circuit” from the L298 data sheet onto an Arduino Shield.
See the entire sketch on github:Step Motor Simple Test
The test software is simple. We use one button to turn left, and the other to turn right. Pressing a button turns the motor 180 degrees in the indicated direction.
// read the pins
int sw1_reading = digitalRead(sw1_pin);
int sw2_reading = digitalRead(sw2_pin);
// if only one switch is high, turn the motor the
// corresponding direction one half revolution.
if ( sw1_reading && ! sw2_reading )
if ( sw2_reading && ! sw1_reading )
Following the advice in the Beginners Guide to Arduino Shield PCB, I then laid this circuit out using EAGLE, and send it off to pcb.laen.org for fabrication. $25 and 14 days later, I have three of these handy purple boards in my hands for all my step motor driving projects.
Note that this will also drive a pair of regular bi-directional DC motors.
This whole setup could be made even smaller and cheaper by using an Arduino Pro Mini from Sparkfun. The next revision of this board will use a 24-pin socket to stick the Pro Mini onto the board.