Step 1: Install
In order to make it work with older versions of the Arduino, you will need to trim a few pins off the motor shield. However, this is not, at all, recommended.
Insert the motor shield pins into the socket of the Arduino Uno.
Step 2: Shield Features
It also has 6 headers for the attachment of Tinkerkit inputs, outputs, and communication lines. The use of these pins is somewhat limited, and therefor not covered in this tutorial.
With an external power supply, the motor shield can safely supply up to 12V and 2A per motor channel (or 4A to a single channel).
There are pins on the Arduino that are always in use by the shield. By addressing these pins you can select a motor channel to initiate, specify the motor direction (polarity), set motor speed (PWM), stop and start the motor, and monitor the current absorption of each channel .
The pin breakdown is as follows:
|Function||Channel A||Channel B|
|Direction||Digital 12||Digital 13|
|Speed (PWM)||Digital 3||Digital 11|
|Brake||Digital 9||Digital 8|
|Current Sensing||Analog 0||Analog 1|
For more information about the technical specs, check out the motor shield's official page on the Arduino site.
Step 3: Program
In order to get the board to do anything, you need to initialize the motor channel by toggling three parameters:
- First you need to set the motor direction (polarity of the power supply) by setting it either HIGH or LOW.
- Then you need to disengage the brake pin for the motor channel by setting it to LOW.
- Finally, to get the motor to start moving, you need to set the speed by sending a PWM command (analogWrite) to the appropriate pin.
If you do not do all three of these things, the motor will not turn on.
In the following steps are some common examples of common motor setups.
Step 4: One Motor
An external power supply is not always necessary, but it drastically improves the motor's performance. It is recommended that you always use one.
To connect your external power supply, connect the positive (red) wire from the power supply to the "Vin" terminal, and the ground (black) wire to the "GND" terminal.
Finally, upload the code to control the Motor Shield to the Arduino.
Here is the code for controlling one motor:
Step 5: Two Motors
The only difference code-wise is that you need to engage a second channel to control the second motor.
Here is code for controlling two motors:
Step 6: Stepper Motor
To figure out which two pins make up a single coil, insert an LED into any two pins on its socket and rotate the motor shaft. If the LED lights up, you found one coil. The other two pins should make up the other coil.
To make a bipolar motor spin:
- Power the first coil.
- Next power the second coil with reverse polarity.
- Then power the first coil with reverse polarity.
- Finally, power the second coil.
Here is code to make the stepper spin in one direction:
Here is code to make the stepper spin in the opposite direction: