But it was. I found almost nothing.
I did get it working eventually though, mostly through trial and error, so now I can explain to other people how it works. (Well, at least how to control DC motors with it.)
First of all, here is a diagram of the board:
This looks complicated, but it's actually quite simple to understand. I could explain what everything does individually, but that would take too long and not be very interesting. Instead, try this simple circuit.
Materials:
- Arduino
- Osepp motor shield
- small DC motor
- 6 volt power supply (a pack of AA batteries will do)
- Start by mounting the motor shield on the Arduino board. Carefully slide all of the leads on the bottom of the shield into the black terminals on the Arduino. They should be around two thirds of the way in. Don't try to force them further, as doing this could make them bend and possibly brake off.
- Next, take the two leads from the motor and insert them into the motor one connectors on the shield. Polarity doesn't matter for now. Grab a screwdriver and tighten the screw terminals until the motor leads are secure.
- Plug the 6v power source into motor VSrc on the top left corner of the board, with the positive terminal on the right and negative on the left. A light should come on.
- Finally, plug a USB cord leaing to you're computer into the USB port on the Arduino board. Open the Arduino IDE and follow the steps to program it, or copy the entire program. Upload it onto the Arduino and watch it go!
Running a DC motor with the motor shield |
Type the following code into the Arduino IDE, or, if you prefer, copy and paste it.
#include <AFMotor.h>
AF_DCMotor myMotor(1, MOTOR34_64KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
myMotor.setSpeed(100); // set the speed to 200 (maximum speed is 255)
}
void loop() {
myMotor.run(FORWARD); //run motor forwards
delay(1000);
myMotor.run(BACKWARD);
delay(1000);
myMotor.run(RELEASE);
delay(1000);
}
Let's go over all those commands.
- #include <AFmotor.h> this command tells the arduino IDE to include commands from the adafruit motor controller library. It must always go at the beginning of the program.
- AF_DCMotor myMotor(1, MOTOR34_64KHZ); this command tells the program to include a motor named myMotor connected to the motor one connectors, which runs at 64 kilohertz. You can change the name of the motor and what connector it's in, but just keep it like this for now.
- myMotor.setSpeed(100); this sets the running speed of myMotor. It can be used once in the setup area, or to change the speed in the loop area.
- myMotor.run(FORWARD/BACKWARD/RELEASE); use this command to turn on or off motors and decide which direction they turn. FORWARD and BACKWARD turn the motor on, and RELEASE turns the motor off.
- delay(1000); this command sets a delay in milliseconds.
Nice man!
ReplyDeleteNice man!
ReplyDeleteNice man!
ReplyDeleteThanks, glad you appreciate this post so much 😆
Delete